aboutsummaryrefslogtreecommitdiffstats
path: root/lib/net
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-15 02:11:20 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-15 02:11:20 +0000
commit3667f15d15a3b021b15a33ea1d1e2159e740aa5d (patch)
tree81cf304ecd43d9a71ce1c49c4f857b70dde76ff3 /lib/net
parent0788dc2ab03beaaf2300970e6d43e01cbc3d7e33 (diff)
downloadruby-3667f15d15a3b021b15a33ea1d1e2159e740aa5d.tar.gz
* lib/net/http.rb (Net::HTTP#connect): use connect_nonblock and
io/wait. fix GH-899 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net')
-rw-r--r--lib/net/http.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 4c1c3271ae..4db69b623b 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -925,7 +925,21 @@ module Net #:nodoc:
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