lib/patronus_fati/connection.rb in patronus_fati-0.9.11 vs lib/patronus_fati/connection.rb in patronus_fati-0.9.12
- old
+ new
@@ -1,8 +1,6 @@
module PatronusFati
- DisconnectError = Class.new(StandardError)
-
class Connection
attr_reader :port, :read_queue, :server, :write_queue
def initialize(server, port)
@server = server
@@ -12,20 +10,21 @@
self.write_queue = Queue.new
end
def connect
establish_connection
+ return unless connected?
start_read_thread
start_write_thread
end
def connected?
- !socket.nil?
+ !(socket.nil? || socket.closed?)
end
def disconnect
- return unless connected?
+ return unless socket
Thread.kill(read_thread)
Thread.kill(write_thread)
socket.close unless socket.closed?