Skip to content

Commit 01ba745

Browse files
committed
Raise an exception if it is specified together with other timeout options
1 parent 51a1cb9 commit 01ba745

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

ext/socket/lib/socket.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,11 @@ def accept_nonblock(exception: true)
657657
# puts sock.read
658658
# }
659659
def self.tcp(host, port, local_host = nil, local_port = nil, connect_timeout: nil, resolv_timeout: nil, open_timeout: nil, fast_fallback: tcp_fast_fallback, &) # :yield: socket
660+
661+
if open_timeout && (connect_timeout || resolv_timeout)
662+
raise ArgumentError, "Cannot specify open_timeout along with connect_timeout or resolv_timeout"
663+
end
664+
660665
sock = if fast_fallback && !(host && ip_address?(host))
661666
tcp_with_fast_fallback(host, port, local_host, local_port, connect_timeout:, resolv_timeout:, open_timeout:)
662667
else

test/socket/test_socket.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,15 @@ def test_tcp_socket_open_timeout
954954
RUBY
955955
end
956956

957+
def test_tcp_socket_open_timeout_with_other_timeouts
958+
opts = %w[-rsocket -W1]
959+
assert_separately opts, <<~RUBY
960+
assert_raise(ArgumentError) do
961+
Socket.tcp("localhost", 12345, open_timeout: 0.01, resolv_timout: 0.01)
962+
end
963+
RUBY
964+
end
965+
957966
def test_tcp_socket_one_hostname_resolution_succeeded_at_least
958967
opts = %w[-rsocket -W1]
959968
assert_separately opts, <<~RUBY

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy