Skip to content
Snippets Groups Projects
Commit da5e69f0 authored by Jeffrey Zhang's avatar Jeffrey Zhang
Browse files

Move client disconnect to seperate function

parent 3d4feade
No related branches found
No related tags found
No related merge requests found
......@@ -75,10 +75,8 @@ class TransactionDeliverer:
proposed_priority = self.next_priority
self.next_priority += 1
pickled_proposed_priority_message = pickle.dumps(
ProposedPriorityMessage(str(uuid4()), self.node_name, transaction_message.sender, transaction_message.transaction_ID, proposed_priority)
)
try:
......@@ -88,15 +86,7 @@ class TransactionDeliverer:
)
except BrokenPipeError:
# Receiving node crashed
if transaction_message.sender in self.client_sockets:
sock = self.client_sockets[transaction_message.sender]
del self.client_sockets[transaction_message.sender]
# Don't shutdown because this causes OSErrer?
#sock.shutdown(socket.SHUT_RDWR)
sock.close()
# TODO think about how to deal with 4-5 second timeout
# reliable unicast
self.disconnect_node(transaction_message.sender)
queue_item = _Transaction_Message_Queue_Item(proposed_priority, self.node_name, transaction_message, 1)
......@@ -147,6 +137,14 @@ class TransactionDeliverer:
while len(self.transactions_queue) > 0 and self.transactions_queue[0].transaction_message.deliverable:
transaction_to_process = self.transactions_queue.pop(0)
self.transaction_executor.transaction(transaction_to_process.transaction_message.transaction)
def disconnect_node(self, client_name):
if client_name in self.client_sockets:
sock = self.client_sockets[client_name]
del self.client_sockets[client_name]
# Don't shutdown because this causes OSError?
#sock.shutdown(socket.SHUT_RDWR)
sock.close()
def multicast(self, client_names_messages):
closed_connections = []
......@@ -163,12 +161,7 @@ class TransactionDeliverer:
closed_connections.append(cn)
for cn in closed_connections:
if cn in self.client_sockets:
sock = self.client_sockets[cn]
del self.client_sockets[cn]
# Don't shutdown because this causes OSError?
#sock.shutdown(socket.SHUT_RDWR)
sock.close()
self.disconnect_node(cn)
def shutdown(self):
for sock in self.client_sockets.values():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment