socketpool 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -25,7 +25,7 @@ class SocketPool
25
25
 
26
26
  # Pool size and timeout.
27
27
  @size = opts[:size] || 2
28
- @timeout = opts[:timeout] || 5.0
28
+ @timeout = opts[:timeout] || 5
29
29
  @eager = opts[:eager] || false
30
30
 
31
31
  # Mutex for synchronizing pool access
@@ -77,17 +77,13 @@ class SocketPool
77
77
 
78
78
  # Adds a new socket to the pool and checks it out.
79
79
  def checkout_new_socket
80
- begin
81
- socket = Socket.new(so_domain(@socktype), so_type(@socktype), 0)
82
- @sockaddr ||= Socket.pack_sockaddr_in(@port, @host) if ![:unix, :unigram].include?(@socktype)
83
- @sockaddr ||= Socket.pack_sockaddr_un(@host) if [:unix, :unigram].include?(@socktype)
84
- socket.connect(@sockaddr)
85
- if @sockopts.size > 0
86
- @sockopts.each{ |opt| socket.setsockopt(opt[:level], opt[:optname], opt[:optval]) }
87
- end
88
- rescue => ex
89
- raise ConnectionFailure, "Failed to connect to host #{@host} and port #{@port}: #{ex}"
90
- end
80
+ socket = Socket.new(so_domain(@socktype), so_type(@socktype), 0)
81
+
82
+ # Pack address for sockets and set any options passed
83
+ @sockaddr ||= Socket.pack_sockaddr_in(@port, @host) if ![:unix, :unigram].include?(@socktype)
84
+ @sockaddr ||= Socket.pack_sockaddr_un(@host) if [:unix, :unigram].include?(@socktype)
85
+ @sockopts.each{ |opt| socket.setsockopt(opt[:level], opt[:optname], opt[:optval]) } if @sockopts.size > 0
86
+ socket.connect(@sockaddr)
91
87
 
92
88
  @checked_out << socket
93
89
  @sockets << socket
@@ -1,6 +1,27 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "SocketPool arguments" do
4
+ before :each do
5
+ begin
6
+ s = TCPSocket.new("127.0.0.1", "11222")
7
+ s.close
8
+ socket_open = true
9
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
10
+ socket_open = false
11
+ end
12
+
13
+ if !socket_open
14
+ @tcp_server = TCPServer.new(11222)
15
+ @udp_server = UDPSocket.new
16
+ @udp_server.bind(nil, 11223)
17
+ end
18
+ end
19
+
20
+ after :each do
21
+ @tcp_server.close if defined?(@tcp_server)
22
+ @udp_server.close if defined?(@udp_server)
23
+ end
24
+
4
25
  describe SocketPool.new('127.0.0.1', '11222') do
5
26
  specify { subject.port.should eq('11222')}
6
27
  specify { subject.host.should eq('127.0.0.1')}
@@ -25,9 +46,9 @@ describe "SocketPool arguments" do
25
46
  end
26
47
 
27
48
  describe "UDP => Eager SocketPool" do
28
- subject { SocketPool.new('127.0.0.1', '11222', :type => :udp, :eager => true) }
49
+ subject { SocketPool.new('127.0.0.1', '11223', :type => :udp, :eager => true) }
29
50
 
30
- specify { subject.port.should eq('11222')}
51
+ specify { subject.port.should eq('11223')}
31
52
  specify { subject.host.should eq('127.0.0.1')}
32
53
  specify { subject.size.should eq(2)}
33
54
  specify { subject.timeout.should eq(5.0)}
@@ -39,9 +60,9 @@ describe "SocketPool arguments" do
39
60
  end
40
61
 
41
62
  describe "UDP => Eager SocketPool => resized, short timeout" do
42
- subject { SocketPool.new('127.0.0.1', '11222', :type => :udp, :eager => true, :size => 19, :timeout => 1) }
63
+ subject { SocketPool.new('127.0.0.1', '11223', :type => :udp, :eager => true, :size => 19, :timeout => 1) }
43
64
 
44
- specify { subject.port.should eq('11222')}
65
+ specify { subject.port.should eq('11223')}
45
66
  specify { subject.host.should eq('127.0.0.1')}
46
67
  specify { subject.size.should eq(19)}
47
68
  specify { subject.timeout.should eq(1.0)}
@@ -57,16 +78,16 @@ describe "SocketPool arguments" do
57
78
  SocketPool.new('127.0.0.1', '11222',
58
79
  :type => :tcp,
59
80
  :eager => true,
60
- :size => 19,
61
- :timeout => 1,
81
+ :size => 7,
82
+ :timeout => 1,
62
83
  :socketopts => [{:level => Socket::IPPROTO_TCP, :optname => Socket::TCP_NODELAY, :optval => 1}])
63
84
  }
64
85
 
65
86
  specify { subject.port.should eq('11222')}
66
87
  specify { subject.host.should eq('127.0.0.1')}
67
- specify { subject.size.should eq(19)}
88
+ specify { subject.size.should eq(7)}
68
89
  specify { subject.timeout.should eq(1.0)}
69
- specify { subject.instance_variable_get(:@sockets).size.should eq(19)}
90
+ specify { subject.instance_variable_get(:@sockets).size.should eq(7)}
70
91
  specify { subject.instance_variable_get(:@checked_out).should eq([])}
71
92
  specify { subject.instance_variable_get(:@eager).should eq(true)}
72
93
  specify { subject.instance_variable_get(:@socktype).should eq(:tcp)}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socketpool
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brandon Dewitt
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-18 00:00:00 -04:00
18
+ date: 2011-08-07 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -108,7 +108,6 @@ files:
108
108
  - .document
109
109
  - .rspec
110
110
  - Gemfile
111
- - Gemfile.lock
112
111
  - LICENSE.txt
113
112
  - README.rdoc
114
113
  - Rakefile
@@ -1,28 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- diff-lcs (1.1.2)
5
- git (1.2.5)
6
- jeweler (1.5.2)
7
- bundler (~> 1.0.0)
8
- git (>= 1.2.5)
9
- rake
10
- rake (0.8.7)
11
- rcov (0.9.9)
12
- rspec (2.3.0)
13
- rspec-core (~> 2.3.0)
14
- rspec-expectations (~> 2.3.0)
15
- rspec-mocks (~> 2.3.0)
16
- rspec-core (2.3.1)
17
- rspec-expectations (2.3.0)
18
- diff-lcs (~> 1.1.2)
19
- rspec-mocks (2.3.0)
20
-
21
- PLATFORMS
22
- ruby
23
-
24
- DEPENDENCIES
25
- bundler (~> 1.0.0)
26
- jeweler (~> 1.5.2)
27
- rcov
28
- rspec (~> 2.3.0)