From 163e979f95d0848d29cafb197d62d152fe2a1b4d Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 28 Jul 2019 18:07:23 +0100 Subject: [PATCH] move socket creation to it's own function, send event just prior to .connect --- src/IRCServer.py | 1 + src/IRCSocket.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/IRCServer.py b/src/IRCServer.py index 69463332..5605814f 100644 --- a/src/IRCServer.py +++ b/src/IRCServer.py @@ -95,6 +95,7 @@ class Server(IRCObject.Object): tls_verify=self.get_setting("ssl-verify", True), cert=self.bot.config.get("tls-certificate", None), key=self.bot.config.get("tls-key", None)) + self.events.on("preprocess.connect").call(server=self) self.socket.connect() if self.connection_params.password: diff --git a/src/IRCSocket.py b/src/IRCSocket.py index f5fe1446..98091aff 100644 --- a/src/IRCSocket.py +++ b/src/IRCSocket.py @@ -58,12 +58,15 @@ class Socket(IRCObject.Object): cert=self._cert, key=self._key, verify=self._tls_verify, hostname=server_hostname) + def _make_socket(self, hostname, port, bindhost, timeout): + return socket.create_connection((hostname, port), timeout, bindhost) + def connect(self): bindhost = None if self._bindhost: bindhost = (self._bindhost, 0) - self._socket = socket.create_connection((self._hostname, self._port), - 5.0, bindhost) + self._socket = self._make_socket(self._hostname, self._port, bindhost, + 5.0) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) if self._tls: