[前][次][番号順一覧][スレッド一覧]

ruby-changes:38351

From: normal <ko1@a...>
Date: Thu, 7 May 2015 05:31:03 +0900 (JST)
Subject: [ruby-changes:38351] normal:r50432 (trunk): stdlib: use IO#wait_*able instead of IO.select when possible

normal	2015-05-07 05:30:43 +0900 (Thu, 07 May 2015)

  New Revision: 50432

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50432

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/lib/socket.rb
    trunk/lib/drb/drb.rb
    trunk/lib/resolv.rb
    trunk/lib/webrick/httpserver.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50431)
+++ ChangeLog	(revision 50432)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu May  7 05:14:39 2015  Eric Wong  <e@8...>
+
+	* 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@r...>
 
 	* vm_eval.c (rb_method_call_status): undefined refined method is
Index: lib/resolv.rb
===================================================================
--- lib/resolv.rb	(revision 50431)
+++ lib/resolv.rb	(revision 50432)
@@ -1,6 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L1
 require 'socket'
 require 'timeout'
 require 'thread'
+require 'io/wait'
 
 begin
   require 'securerandom'
@@ -680,7 +681,11 @@ class Resolv https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L681
           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
Index: lib/webrick/httpserver.rb
===================================================================
--- lib/webrick/httpserver.rb	(revision 50431)
+++ lib/webrick/httpserver.rb	(revision 50432)
@@ -8,6 +8,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpserver.rb#L8
 #
 # $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 https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpserver.rb#L73
         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
Index: lib/drb/drb.rb
===================================================================
--- lib/drb/drb.rb	(revision 50431)
+++ lib/drb/drb.rb	(revision 50432)
@@ -48,6 +48,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/drb/drb.rb#L48
 require 'socket'
 require 'thread'
 require 'fcntl'
+require 'io/wait'
 require 'drb/eq'
 
 #
@@ -1003,7 +1004,7 @@ module DRb https://github.com/ruby/ruby/blob/trunk/lib/drb/drb.rb#L1004
     # 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
Index: ext/socket/lib/socket.rb
===================================================================
--- ext/socket/lib/socket.rb	(revision 50431)
+++ ext/socket/lib/socket.rb	(revision 50432)
@@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L1
 require 'socket.so'
+require 'io/wait'
 
 class Addrinfo
   # creates an Addrinfo object from the arguments.
@@ -54,9 +55,8 @@ class Addrinfo https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L55
         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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]