lib/patronus_fati/connection.rb in patronus_fati-0.8.13 vs lib/patronus_fati/connection.rb in patronus_fati-0.8.14
- old
+ new
@@ -1,6 +1,8 @@
module PatronusFati
+ DisconnectError = Class.new(StandardError)
+
class Connection
attr_reader :port, :read_queue, :server, :write_queue
def initialize(server, port)
@server = server
@@ -54,14 +56,17 @@
self.read_thread = Thread.new do
begin
while (line = socket.readline)
read_queue << line
end
+ rescue EOFError => e
+ raise DisconnectError
rescue => e
- $stderr.puts format('Error in read thread: %s', e.message)
+ $stderr.puts format('Error in read thread: %s %s', e.class.to_s, e.message)
+ $stderr.puts e.backtrace
ensure
- socket.close
+ socket.close if socket
end
end
end
def start_write_thread
@@ -71,12 +76,13 @@
while (msg = write_queue.pop)
socket.write("!%i %s\r\n" % [count, msg])
count += 1
end
rescue => e
- $stderr.puts format('Error in write thread: %s', e.message)
+ $stderr.puts format('Error in write thread: %s %s', e.class.to_s, e.message)
+ $stderr.puts e.backtrace
ensure
- socket.close
+ socket.close if socket
end
end
end
end
end