def _connect(self): """Connect to the RabbitMQ Server :raises: ConnectionException """ self._set_state(self.OPENING) sock = None for (af, socktype, proto, canonname, sockaddr) in self._get_addr_info(): try: sock = self._create_socket(af, socktype, proto) self._connect_socket(sock, sockaddr) break except socket.error as error: LOGGER.debug('Error connecting to %r: %s', sockaddr, error) sock = None continue if not sock: args = [ self._args['host'], self._args['port'], 'Could not connect' ] self._exceptions.put(exceptions.ConnectionException(*args)) self._events.set(events.EXCEPTION_RAISED) return self._socket = sock self._socket.settimeout(0) self._events.set(events.SOCKET_OPENED) self._set_state(self.OPEN)
def on_error(self, exception): """Common functions when a socket error occurs. Make sure to set closed and add the exception, and note an exception event. :param socket.error exception: The socket error """ args = [self._args['host'], self._args['port'], str(exception)] if self._channels[0][0].open: self._exceptions.put(exceptions.ConnectionResetException(*args)) else: self._exceptions.put(exceptions.ConnectionException(*args)) self._events.set(events.EXCEPTION_RAISED)