SocketPipe shouldn't close the socket.

This is a layering violation - the SocketPipe doesn't own
the socket and provides no other way to close the socket, leading
to unnecessary complexity like that in interface.py.

I looked at deamon.py and NetworkProxy - the two other users,
and they don't close the sockets explicitly, just let them be
garbage collected.
This commit is contained in:
Neil Booth 2015-06-04 16:30:59 +09:00
parent 90d7179d73
commit 2f2e468d0a
2 changed files with 3 additions and 7 deletions

View File

@ -61,7 +61,6 @@ class TcpInterface(threading.Thread):
# closing the socket # closing the socket
self.disconnect = False self.disconnect = False
self._status = CS_OPENING self._status = CS_OPENING
self.needs_shutdown = True
self.debug = False # dump network messages. can be changed at runtime using the console self.debug = False # dump network messages. can be changed at runtime using the console
self.message_id = 0 self.message_id = 0
self.response_queue = response_queue self.response_queue = response_queue
@ -304,7 +303,6 @@ class TcpInterface(threading.Thread):
return return
# If remote side closed the socket, SocketPipe closes our socket and returns None # If remote side closed the socket, SocketPipe closes our socket and returns None
if response is None: if response is None:
self.needs_shutdown = False # Don't re-close the socket
self.disconnect = True self.disconnect = True
self.print_error("connection closed remotely") self.print_error("connection closed remotely")
else: else:
@ -323,9 +321,8 @@ class TcpInterface(threading.Thread):
self.maybe_ping() self.maybe_ping()
self.send_requests() self.send_requests()
self.get_and_process_response() self.get_and_process_response()
if self.needs_shutdown: s.shutdown(socket.SHUT_RDWR)
s.shutdown(socket.SHUT_RDWR) s.close()
s.close()
# Also for the s is None case # Also for the s is None case
self._status = CS_FAILED self._status = CS_FAILED

View File

@ -360,8 +360,7 @@ class SocketPipe:
traceback.print_exc(file=sys.stderr) traceback.print_exc(file=sys.stderr)
data = '' data = ''
if not data: if not data: # Connection closed remotely
self.socket.close()
return None return None
self.message += data self.message += data
self.recv_time = time.time() self.recv_time = time.time()