1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
normal 2015-05-06 20:30:43 +00:00
parent 8e08552ed0
commit 84b012e02a
5 changed files with 20 additions and 5 deletions

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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