- handle teardown

This commit is contained in:
Jordan Sissel 2012-12-31 15:30:21 -08:00
parent 8de740e17a
commit f353b7aff5

View file

@ -93,10 +93,12 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
public
def run(output_queue)
if server?
@thread = Thread.current
@client_threads = []
loop do
# Start a new thread for each connection.
begin
Thread.start(@server_socket.accept) do |s|
@client_threads << Thread.start(@server_socket.accept) do |s|
# TODO(sissel): put this block in its own method.
# monkeypatch a 'peer' method onto the socket.
@ -108,7 +110,11 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
end # Thread.start
rescue IOError
if @interrupted
#Intended shutdown, get out of the loop
# Intended shutdown, get out of the loop
@server_socket.close
@client_threads.each do |thread|
thread.raise(IOError.new)
end
break
else
# Else it was a genuine IOError caused by something else, so propagate it up..
@ -130,7 +136,7 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
def teardown
if server?
@interrupted = true
@server_socket.close
@thread.raise(IOError.new)
end
end # def teardown
end # class LogStash::Inputs::Tcp