socketpool 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/socketpool.rb +14 -12
  3. metadata +4 -4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
data/lib/socketpool.rb CHANGED
@@ -59,15 +59,17 @@ class SocketPool
59
59
 
60
60
  # Return a socket to the pool.
61
61
  # Allow for destroying a resetting socket if the application determines the connection is no good
62
- def checkin(socket, reset=false)
62
+ def checkin(sock, reset=false)
63
63
  @connection_mutex.synchronize do
64
64
  if reset
65
- @sockets.delete(socket)
66
- @checked_out.delete(socket)
67
- socket = checkout_new_socket
65
+ @sockets.delete(sock)
66
+ @checked_out.delete(sock)
67
+ @pids.delete(sock)
68
+ sock.close
69
+ sock = checkout_new_socket
68
70
  end
69
71
 
70
- @checked_out.delete(socket)
72
+ @checked_out.delete(sock)
71
73
  @queue.signal
72
74
  end
73
75
  true
@@ -76,13 +78,13 @@ class SocketPool
76
78
  # Adds a new socket to the pool and checks it out.
77
79
  def checkout_new_socket
78
80
  begin
79
- socket = Socket.new(so_domain(@socktype), so_type(@socktype), 0)
80
- @sockaddr ||= Socket.pack_sockaddr_in(@port, @host) if ![:unix, :unigram].include?(@socktype)
81
- @sockaddr ||= Socket.pack_sockaddr_un(@host) if [:unix, :unigram].include?(@socktype)
82
- socket.connect(@sockaddr)
83
- if @sockopts.size > 0
84
- @sockopts.each{ |opt| socket.setsockopt(opt[:level], opt[:optname], opt[:optval]) }
85
- end
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
86
88
  rescue => ex
87
89
  raise ConnectionFailure, "Failed to connect to host #{@host} and port #{@port}: #{ex}"
88
90
  end
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: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
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-17 00:00:00 -04:00
18
+ date: 2011-04-18 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency