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

ruby-changes:38826

From: naruse <ko1@a...>
Date: Mon, 15 Jun 2015 11:11:50 +0900 (JST)
Subject: [ruby-changes:38826] naruse:r50907 (trunk): * lib/net/http.rb (Net::HTTP#connect): use connect_nonblock and

naruse	2015-06-15 11:11:20 +0900 (Mon, 15 Jun 2015)

  New Revision: 50907

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

  Log:
    * lib/net/http.rb (Net::HTTP#connect): use connect_nonblock and
      io/wait. fix GH-899

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/http.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50906)
+++ ChangeLog	(revision 50907)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jun 15 02:26:34 2015  NARUSE, Yui  <naruse@r...>
+
+	* lib/net/http.rb (Net::HTTP#connect): use connect_nonblock and
+	  io/wait to eliminate timeout use. fix GH-899
+
 Sat Jun 13 07:21:18 2015  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* thread.c (thread_start_func_2): don't interrupt when last thread
Index: lib/net/http.rb
===================================================================
--- lib/net/http.rb	(revision 50906)
+++ lib/net/http.rb	(revision 50907)
@@ -925,7 +925,21 @@ module Net   #:nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L925
           end
           # Server Name Indication (SNI) RFC 3546
           s.hostname = @address if s.respond_to? :hostname=
-          Timeout.timeout(@open_timeout, Net::OpenTimeout) { s.connect }
+          if timeout = @open_timeout
+            while true
+              raise Net::OpenTimeout if timeout <= 0
+              start = Process.clock_gettime Process::CLOCK_MONOTONIC
+              # to_io is requied because SSLSocket doesn't have wait_readable yet
+              case s.connect_nonblock(exception: false)
+              when :wait_readable; s.to_io.wait_readable(timeout)
+              when :wait_writable; s.to_io.wait_writable(timeout)
+              else; break
+              end
+              timeout -= Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
+            end
+          else
+            s.connect
+          end
           if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
             s.post_connection_check(@address)
           end

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

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