resilient_socket 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- begin
552
- @socket.connect_nonblock(socket_address)
553
- rescue Errno::EINPROGRESS
554
- end
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::EISCONN
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
@@ -1,3 +1,3 @@
1
1
  module ResilientSocket #:nodoc
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -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.3.2
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-08 00:00:00.000000000 Z
12
+ date: 2012-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: semantic_logger