Skip to content

Commit

Permalink
Add a close method to connections and pools.
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Rarick committed Feb 1, 2008
1 parent ffb0bbc commit 6d36d50
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/beanstalk-client/connection.rb
Expand Up @@ -29,13 +29,22 @@ class RawConnection
def initialize(addr, jptr=self)
@addr = addr
@jptr = jptr
connect
end

def connect
host, port = addr.split(':')
@socket = TCPSocket.new(host, port.to_i)

# Don't leak fds when we exec.
@socket.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
end

def close
@socket.close
@socket = nil
end

def put(body, pri=65536, delay=0, ttr=120)
@socket.write("put #{pri} #{delay} #{ttr} #{body.size}\r\n#{body}\r\n")
check_resp('INSERTED', 'BURIED')[0].to_i
Expand Down Expand Up @@ -255,6 +264,13 @@ def remove(conn)
@connections.delete(conn.addr)
end

def close
while @connections.size > 0
addr, conn = @connections.pop
conn.close
end
end

def peek()
open_connections.each do |c|
job = c.peek
Expand Down

0 comments on commit 6d36d50

Please sign in to comment.