ruby-changes:38442
From: normal <ko1@a...>
Date: Sun, 17 May 2015 17:22:36 +0900 (JST)
Subject: [ruby-changes:38442] normal:r50523 (trunk): lib/webrick/utils.rb: simplify by avoiding fcntl
normal 2015-05-17 17:22:11 +0900 (Sun, 17 May 2015) New Revision: 50523 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50523 Log: 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] Modified files: trunk/ChangeLog trunk/lib/webrick/utils.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 50522) +++ ChangeLog (revision 50523) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun May 17 17:21:29 2015 Eric Wong <e@8...> + + * lib/webrick/utils.rb (set_non_blocking): use IO#nonblock= + * (set_close_on_exec): use IO#close_on_exec= + [Feature #11136] + Sun May 17 15:01:26 2015 Nobuyoshi Nakada <nobu@r...> * numeric.c (num_positive_p, num_negative_p): add methods Index: lib/webrick/utils.rb =================================================================== --- lib/webrick/utils.rb (revision 50522) +++ lib/webrick/utils.rb (revision 50523) @@ -9,7 +9,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L9 # $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 https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L17 ## # 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/