summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-17 08:22:11 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-17 08:22:11 +0000
commit29a914ff2ee0fcf4b1a664355c99e4a16e766c9f (patch)
treec7c591474d48c5a43e891a3c930398277e3846f4 /lib
parent932e916b9e340d3ae52bac2eb57567208dc21d4f (diff)
lib/webrick/utils.rb: simplify by avoiding fcntl
IO#nonblock= and IO#close_on_exec= methods are simpler-to-use and potentially more portable to for future OSes. IO#nonblock= and IO#close_on_exec= are also smart enough to avoid redundantly setting flags so a syscall may be avoided. These methods could probably be removed entirely and inlined, but it's unclear if there is 3rd-party code which relies on them. * lib/webrick/utils.rb (set_non_blocking): use IO#nonblock= * (set_close_on_exec): use IO#close_on_exec= [Feature #11136] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/webrick/utils.rb12
1 files changed, 3 insertions, 9 deletions
diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb
index 5be4db8c0d..bde3d01ca5 100644
--- a/lib/webrick/utils.rb
+++ b/lib/webrick/utils.rb
@@ -9,7 +9,7 @@
# $IPR: utils.rb,v 1.10 2003/02/16 22:22:54 gotoyuzo Exp $
require 'socket'
-require 'fcntl'
+require 'io/nonblock'
require 'etc'
module WEBrick
@@ -17,20 +17,14 @@ module WEBrick
##
# Sets IO operations on +io+ to be non-blocking
def set_non_blocking(io)
- flag = File::NONBLOCK
- if defined?(Fcntl::F_GETFL)
- flag |= io.fcntl(Fcntl::F_GETFL)
- end
- io.fcntl(Fcntl::F_SETFL, flag)
+ io.nonblock = true if io.respond_to?(:nonblock=)
end
module_function :set_non_blocking
##
# Sets the close on exec flag for +io+
def set_close_on_exec(io)
- if defined?(Fcntl::FD_CLOEXEC)
- io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
- end
+ io.close_on_exec = true if io.respond_to?(:close_on_exec=)
end
module_function :set_close_on_exec