dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] lib/net/*: use io/wait methods instead of IO.select
Date: Mon, 13 Apr 2015 02:22:17 +0000	[thread overview]
Message-ID: <1428891737-5623-1-git-send-email-e@80x24.org> (raw)

io/wait is expected to work on any platform where sockets are
supported.  io/wait methods uses fewer allocations and uses
ppoll internally under Linux for better performance on
high-numbered FDs.

[ruby-core:35572] describes the performance advantage of ppoll
on high-numbered FDs.

* lib/net/protocol.rb (rbuf_fill): use IO#wait_*able
* lib/net/http/generic_request.rb (wait_for_continue): ditto
---
 lib/net/http/generic_request.rb | 2 +-
 lib/net/protocol.rb             | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/net/http/generic_request.rb b/lib/net/http/generic_request.rb
index 00ff434..9b7d287 100644
--- a/lib/net/http/generic_request.rb
+++ b/lib/net/http/generic_request.rb
@@ -309,7 +309,7 @@ class Net::HTTPGenericRequest
   def wait_for_continue(sock, ver)
     if ver >= '1.1' and @header['expect'] and
         @header['expect'].include?('100-continue')
-      if IO.select([sock.io], nil, nil, sock.continue_timeout)
+      if sock.io.to_io.wait_readable(sock.continue_timeout)
         res = Net::HTTPResponse.read_new(sock)
         unless res.kind_of?(Net::HTTPContinue)
           res.decode_content = @decode_content
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index 5a20c5d..28833a2 100644
--- a/lib/net/protocol.rb
+++ b/lib/net/protocol.rb
@@ -20,6 +20,7 @@
 
 require 'socket'
 require 'timeout'
+require 'io/wait'
 
 module Net # :nodoc:
 
@@ -153,12 +154,12 @@ module Net # :nodoc:
       when String
         return @rbuf << rv
       when :wait_readable
-        IO.select([@io], nil, nil, @read_timeout) or raise Net::ReadTimeout
+        @io.to_io.wait_readable(@read_timeout) or raise Net::ReadTimeout
         # continue looping
       when :wait_writable
         # OpenSSL::Buffering#read_nonblock may fail with IO::WaitWritable.
         # http://www.openssl.org/support/faq.html#PROG10
-        IO.select(nil, [@io], nil, @read_timeout) or raise Net::ReadTimeout
+        @io.to_io.wait_writable(@read_timeout) or raise Net::ReadTimeout
         # continue looping
       when nil
         # callers do not care about backtrace, so avoid allocating for it
-- 
EW


                 reply	other threads:[~2015-04-13  2:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428891737-5623-1-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).