Commit 53af87bf authored by Guillaume Seguin's avatar Guillaume Seguin

Harden against network errors

parent 9632556c
...@@ -89,7 +89,10 @@ class printcore(): ...@@ -89,7 +89,10 @@ class printcore():
self.stop_read_thread = True self.stop_read_thread = True
self.read_thread.join() self.read_thread.join()
self.read_thread = None self.read_thread = None
try:
self.printer.close() self.printer.close()
except socket.error:
pass
self.printer = None self.printer = None
self.online = False self.online = False
self.printing = False self.printing = False
...@@ -156,7 +159,7 @@ class printcore(): ...@@ -156,7 +159,7 @@ class printcore():
try: try:
line = self.printer.readline() line = self.printer.readline()
if self.printer_tcp and not line: if self.printer_tcp and not line:
raise OSError("Read EOF from socket") raise OSError(-1, "Read EOF from socket")
except socket.timeout: except socket.timeout:
return "" return ""
...@@ -177,6 +180,9 @@ class printcore(): ...@@ -177,6 +180,9 @@ class printcore():
except SerialException as e: except SerialException as e:
print "Can't read from printer (disconnected?) (SerialException {0}): {1}".format(e.errno, e.strerror) print "Can't read from printer (disconnected?) (SerialException {0}): {1}".format(e.errno, e.strerror)
return None return None
except socket.error as e:
print "Can't read from printer (disconnected?) (Socket error {0}): {1}".format(e.errno, e.strerror)
return None
except OSError as e: except OSError as e:
print "Can't read from printer (disconnected?) (OS Error {0}): {1}".format(e.errno, e.strerror) print "Can't read from printer (disconnected?) (OS Error {0}): {1}".format(e.errno, e.strerror)
return None return None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment