[ruby/net-protocol] Add Net::Protocol::TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT

* To find out efficiently if TCPSocket#initialize supports the open_timeout keyword argument.

https://github.com/ruby/net-protocol/commit/738c06f950
This commit is contained in:
Benoit Daloze 2025-12-08 13:06:08 +01:00 committed by Hiroshi SHIBATA
parent 4d7db86a79
commit fda7019c80
Notes: git 2025-12-26 02:02:29 +00:00

View File

@ -54,6 +54,16 @@ module Net # :nodoc:
s.connect
end
end
tcp_socket_parameters = TCPSocket.instance_method(:initialize).parameters
TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT = if tcp_socket_parameters != [[:rest]]
tcp_socket_parameters.include?([:key, :open_timeout])
else
# Use Socket.tcp to find out since there is no parameters information for TCPSocket#initialize
# See discussion in https://github.com/ruby/net-http/pull/224
Socket.method(:tcp).parameters.include?([:key, :open_timeout])
end
private_constant :TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT
end