resilient_socket 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/resilient_socket/tcp_client.rb +14 -8
- data/lib/resilient_socket/version.rb +1 -1
- data/test/tcp_client_test.rb +12 -0
- metadata +2 -2
@@ -127,6 +127,7 @@ module ResilientSocket
|
|
127
127
|
#
|
128
128
|
# :connect_timeout [Float]
|
129
129
|
# Time in seconds to timeout when trying to connect to the server
|
130
|
+
# A value of -1 will cause the connect wait time to be infinite
|
130
131
|
# Default: Half of the :read_timeout ( 30 seconds )
|
131
132
|
#
|
132
133
|
# :log_level [Symbol]
|
@@ -548,17 +549,22 @@ module ResilientSocket
|
|
548
549
|
begin
|
549
550
|
@socket = Socket.new(Socket.const_get(address[0][0]), Socket::SOCK_STREAM, 0)
|
550
551
|
@socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) unless buffered
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
if IO.select(nil, [@socket], nil, @connect_timeout)
|
552
|
+
if @connect_timeout == -1
|
553
|
+
# Timeout of -1 means wait forever for a connection
|
554
|
+
@socket.connect(socket_address)
|
555
|
+
else
|
556
556
|
begin
|
557
557
|
@socket.connect_nonblock(socket_address)
|
558
|
-
rescue Errno::
|
558
|
+
rescue Errno::EINPROGRESS
|
559
|
+
end
|
560
|
+
if IO.select(nil, [@socket], nil, @connect_timeout)
|
561
|
+
begin
|
562
|
+
@socket.connect_nonblock(socket_address)
|
563
|
+
rescue Errno::EISCONN
|
564
|
+
end
|
565
|
+
else
|
566
|
+
raise(ConnectionTimeout.new("Timedout after #{@connect_timeout} seconds trying to connect to #{server}"))
|
559
567
|
end
|
560
|
-
else
|
561
|
-
raise(ConnectionTimeout.new("Timedout after #{@connect_timeout} seconds trying to connect to #{server}"))
|
562
568
|
end
|
563
569
|
break
|
564
570
|
rescue SystemCallError => exception
|
data/test/tcp_client_test.rb
CHANGED
@@ -75,6 +75,18 @@ class TCPClientTest < Test::Unit::TestCase
|
|
75
75
|
assert_equal 'sleep', reply['result']
|
76
76
|
@client.close
|
77
77
|
end
|
78
|
+
|
79
|
+
should "support infinite timeout" do
|
80
|
+
@client = ResilientSocket::TCPClient.new(
|
81
|
+
:server => @server_name,
|
82
|
+
:connect_timeout => -1
|
83
|
+
)
|
84
|
+
request = { 'action' => 'test1' }
|
85
|
+
@client.write(BSON.serialize(request))
|
86
|
+
reply = read_bson_document(@client)
|
87
|
+
assert_equal 'test1', reply['result']
|
88
|
+
@client.close
|
89
|
+
end
|
78
90
|
end
|
79
91
|
|
80
92
|
context "with client connection" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resilient_socket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: semantic_logger
|