Skip to content

Commit 69b2bbc

Browse files
authored
Merge pull request #10 from mohamedhafez/patch-1
Replace Timeout.timeout in Net:HTTP#connect
2 parents 83a6b17 + 753cae3 commit 69b2bbc

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/net/http.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -987,14 +987,13 @@ def connect
987987
end
988988

989989
D "opening connection to #{conn_addr}:#{conn_port}..."
990-
s = Timeout.timeout(@open_timeout, Net::OpenTimeout) {
991-
begin
992-
TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
993-
rescue => e
994-
raise e, "Failed to open TCP connection to " +
995-
"#{conn_addr}:#{conn_port} (#{e.message})"
996-
end
997-
}
990+
begin
991+
s = Socket.tcp conn_addr, conn_port, @local_host, @local_port, connect_timeout: @open_timeout
992+
rescue => e
993+
e = Net::OpenTimeout.new(e) if e.is_a?(Errno::ETIMEDOUT) #for compatibility with previous versions
994+
raise e, "Failed to open TCP connection to " +
995+
"#{conn_addr}:#{conn_port} (#{e.message})"
996+
end
998997
s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
999998
D "opened"
1000999
if use_ssl?

0 commit comments

Comments
 (0)