summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-06 20:30:43 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-06 20:30:43 +0000
commit84b012e02a567f79dc3061cd860be982f95be048 (patch)
tree78dc35d87193481c49ff2c0ec1c2dd30639867be
parent8e08552ed01e827b4e3ca3e0d57695a8737cb394 (diff)
stdlib: use IO#wait_*able instead of IO.select when possible
In case a process encounters high-numbered FDs, this allows consistent performance on systems with ppoll support. [ruby-core:35572] * ext/socket/lib/socket.rb (connect_nonblock): use IO#wait_writable * lib/drb/drb.rb (DRB::DRbTCPSocket#alive?): use IO#wait_readable * lib/webrick/httpserver.rb (run): ditto * lib/resolv.rb (request): ditto for single socket case [ruby-core:68943] [Feature #11081] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50432 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--ext/socket/lib/socket.rb4
-rw-r--r--lib/drb/drb.rb3
-rw-r--r--lib/resolv.rb7
-rw-r--r--lib/webrick/httpserver.rb3
5 files changed, 20 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 32a7ba6..fc289dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu May 7 05:14:39 2015 Eric Wong <e@80x24.org>
+
+ * ext/socket/lib/socket.rb (connect_nonblock): use IO#wait_writable
+ * lib/drb/drb.rb (DRB::DRbTCPSocket#alive?): use IO#wait_readable
+ * lib/webrick/httpserver.rb (run): ditto
+ * lib/resolv.rb (request): ditto for single socket case
+ [ruby-core:68943] [Feature #11081]
+
Wed May 6 22:49:54 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_eval.c (rb_method_call_status): undefined refined method is
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index 2723f7b..7c66e8f 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -1,4 +1,5 @@
require 'socket.so'
+require 'io/wait'
class Addrinfo
# creates an Addrinfo object from the arguments.
@@ -54,9 +55,8 @@ class Addrinfo
when 0 # success or EISCONN, other errors raise
break
when :wait_writable
- if !IO.select(nil, [sock], nil, timeout)
+ sock.wait_writable(timeout) or
raise Errno::ETIMEDOUT, 'user specified timeout'
- end
end while true
else
sock.connect(self)
diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb
index e7a8d20..32e5bfb 100644
--- a/lib/drb/drb.rb
+++ b/lib/drb/drb.rb
@@ -48,6 +48,7 @@
require 'socket'
require 'thread'
require 'fcntl'
+require 'io/wait'
require 'drb/eq'
#
@@ -1003,7 +1004,7 @@ module DRb
# Check to see if this connection is alive.
def alive?
return false unless @socket
- if IO.select([@socket], nil, nil, 0)
+ if @socket.to_io.wait_readable(0)
close
return false
end
diff --git a/lib/resolv.rb b/lib/resolv.rb
index e67dff9..9083bd0 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -1,6 +1,7 @@
require 'socket'
require 'timeout'
require 'thread'
+require 'io/wait'
begin
require 'securerandom'
@@ -680,7 +681,11 @@ class Resolv
if timeout <= 0
raise ResolvTimeout
end
- select_result = IO.select(@socks, nil, nil, timeout)
+ if @socks.size == 1
+ select_result = @socks[0].wait_readable(timeout) ? [ @socks ] : nil
+ else
+ select_result = IO.select(@socks, nil, nil, timeout)
+ end
if !select_result
after_select = Time.now
next if after_select < timelimit
diff --git a/lib/webrick/httpserver.rb b/lib/webrick/httpserver.rb
index 0618489..96bd3fa 100644
--- a/lib/webrick/httpserver.rb
+++ b/lib/webrick/httpserver.rb
@@ -8,6 +8,7 @@
#
# $IPR: httpserver.rb,v 1.63 2002/10/01 17:16:32 gotoyuzo Exp $
+require 'io/wait'
require 'webrick/server'
require 'webrick/httputils'
require 'webrick/httpstatus'
@@ -72,7 +73,7 @@ module WEBrick
begin
timeout = @config[:RequestTimeout]
while timeout > 0
- break if IO.select([sock], nil, nil, 0.5)
+ break if sock.to_io.wait_readable(0.5)
break if @status != :Running
timeout -= 0.5
end