def close_connection(self): if self.isOpen(): eventloop.stop_handling_socket(self.socket) self.stopReadTimeout() self.socket.close() self.socket = None if self.connectionErrback is not None: error = NetworkError(_("Connection closed")) trap_call(self, self.connectionErrback, error) self.connectionErrback = None
def handleSocketError(self, code, msg, operation): if code in (socket.SSL_ERROR_WANT_READ, socket.SSL_ERROR_WANT_WRITE): if self.interruptedOperation is None: self.interruptedOperation = operation elif self.interruptedOperation != operation: signals.system.failed("When talking to the network", details="socket error for the wrong SSL operation") self.close_connection() return eventloop.stop_handling_socket(self.socket) if code == socket.SSL_ERROR_WANT_READ: eventloop.add_read_callback(self.socket, self.onReadReady) else: eventloop.add_write_callback(self.socket, self.onWriteReady) elif code in (socket.SSL_ERROR_ZERO_RETURN, socket.SSL_ERROR_SSL, socket.SSL_ERROR_SYSCALL, socket.SSL_ERROR_EOF): self.handleEarlyClose(operation) else: super(AsyncSSLStream, self).handleSocketError(code, msg, operation)