Skip to content

Commit 738c06f

Browse files
committed
Add Net::Protocol::TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT
* To find out efficiently if TCPSocket#initialize supports the open_timeout keyword argument.
1 parent e376022 commit 738c06f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/net/protocol.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ def ssl_socket_connect(s, timeout)
5454
s.connect
5555
end
5656
end
57+
58+
tcp_socket_parameters = TCPSocket.instance_method(:initialize).parameters
59+
TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT = if tcp_socket_parameters != [[:rest]]
60+
tcp_socket_parameters.include?([:key, :open_timeout])
61+
else
62+
# Use Socket.tcp to find out since there is no parameters information for TCPSocket#initialize
63+
# See discussion in https://github.com/ruby/net-http/pull/224
64+
Socket.method(:tcp).parameters.include?([:key, :open_timeout])
65+
end
66+
private_constant :TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT
5767
end
5868

5969

0 commit comments

Comments
 (0)