move socket creation to it's own function, send event just prior to .connect

This commit is contained in:
jesopo 2019-07-28 18:07:23 +01:00
parent 9827feeabd
commit 163e979f95
2 changed files with 6 additions and 2 deletions

View file

@ -95,6 +95,7 @@ class Server(IRCObject.Object):
tls_verify=self.get_setting("ssl-verify", True), tls_verify=self.get_setting("ssl-verify", True),
cert=self.bot.config.get("tls-certificate", None), cert=self.bot.config.get("tls-certificate", None),
key=self.bot.config.get("tls-key", None)) key=self.bot.config.get("tls-key", None))
self.events.on("preprocess.connect").call(server=self)
self.socket.connect() self.socket.connect()
if self.connection_params.password: if self.connection_params.password:

View file

@ -58,12 +58,15 @@ class Socket(IRCObject.Object):
cert=self._cert, key=self._key, verify=self._tls_verify, cert=self._cert, key=self._key, verify=self._tls_verify,
hostname=server_hostname) hostname=server_hostname)
def _make_socket(self, hostname, port, bindhost, timeout):
return socket.create_connection((hostname, port), timeout, bindhost)
def connect(self): def connect(self):
bindhost = None bindhost = None
if self._bindhost: if self._bindhost:
bindhost = (self._bindhost, 0) bindhost = (self._bindhost, 0)
self._socket = socket.create_connection((self._hostname, self._port), self._socket = self._make_socket(self._hostname, self._port, bindhost,
5.0, bindhost) 5.0)
self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
if self._tls: if self._tls: