From b9fd3869f4eb18bc49b509e4e1472b94d6c1642f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Fri, 2 Feb 2018 10:37:06 +0100 Subject: [PATCH] Move the socket closing function into the server class. --- matrix/server.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/matrix/server.py b/matrix/server.py index da1e274..cf899f2 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -304,13 +304,18 @@ class MatrixServer: server_buffer_prnt(self, message) + def _close_socket(self): + # type: (socket.socket) -> None + if self.socket: + self.socket.shutdown(socket.SHUT_RDWR) + self.socket.close() + def disconnect(self, reconnect=True): # type: (MatrixServer) -> None if self.fd_hook: W.unhook(self.fd_hook) - if self.socket: - close_socket(self.socket) + self._close_socket() self.fd_hook = None self.socket = None @@ -484,7 +489,3 @@ def send_cb(server_name, file_descriptor): return W.WEECHAT_RC_OK -def close_socket(sock): - # type: (socket.socket) -> None - sock.shutdown(socket.SHUT_RDWR) - sock.close()