Handle lost connection.
196063
def connection_lost(self, exc):
        """"""
        _LOGGER.debug('Connection lost with %s', self.transport.serial)
        if exc:
            _LOGGER.error(exc)
            self.transport.serial.close()
            self.conn_lost_callback()
        self.transport = None
836220
def _reconnect(self):
        """"""
        self.close()
        self._db = psycopg2.connect(**self._db_args)

        if self._search_path:
            self.execute('set search_path=%s;' % self._search_path)

        if self._timezone:
            self.execute("set timezone='%s';" % self._timezone)
583779
def connection_lost(self, exc):
        '''
        
        '''
        self._connected = False

        logging.debug(
            'Connection lost (address: {} port: {})'
            .format(self.remote_ip, self.port))

        for pid, (future, task) in self._requests.items():
            task.cancel()
            if future.cancelled():
                continue
            future.set_exception(ConnectionError(
                'Connection is lost before we had an answer on package id: {}.'
                .format(pid)))

        self.on_connection_lost(exc)
967746
def disconnect(self):
        """"""
        # here we just request the disconnection
        # later in _handle_eio_disconnect we invoke the disconnect handler
        for n in self.namespaces:
            self._send_packet(packet.Packet(packet.DISCONNECT, namespace=n))
        self._send_packet(packet.Packet(
            packet.DISCONNECT, namespace='/'))
        self.eio.disconnect(abort=True)
1369153
private void doConnect() throws SessionTimeOutException{
        long to = getConnectTimeOut();

        if(clientSocket.isConnected()){
            ErrorCode ec = sendConnectProtocol(to);
            // CONNECTION_LOSS means client data is inconsistence with server. now we check the last dxid of client.
            // if dxid of the client is bigger than server actual dxid, return CONNECTION_LOSS.
            if(ErrorCode.SESSION_EXPIRED.equals(ec) || ErrorCode.CONNECTION_LOSS.equals(equals(ec))){
                LOGGER.info("Session Expired, cleanup the client session.");
                cleanupSession();
            }
        }
    }
95608
def connectionLost(self, reason):
        """"""
        self.factory.loader.db.session.commit()
        if reactor.running:
            reactor.stop()
859588
def disconnect(self, reason):
        """"""
        self._server._disconnect_client(self._conn_key, self, reason)
792659
def handle_error(_, client_addr):
        """"""
        exc_type, exc_value, _ = sys.exc_info()
        if exc_type is socket.error and exc_value[0] == 32:
            pass
        elif exc_type is cPickle.UnpicklingError:
            sys.stderr.write('Invalid connection from {0}\n'
                             .format(client_addr[0]))
        else:
            raise
885454
def close_connection (self):
        """"""
        if self.url_connection is not None:
            try:
                self.url_connection.quit()
            except Exception:
                pass
            self.url_connection = None
586072
def _try_reconnect(self):
        """"""

        try:
            if self.connection_interrupted:
                self.connect_direct(self.connection_string, force=True)
                self.connection_interrupted = False
                self.connected = True

                # Reenable streaming interface if that was open before as well
                if self._reports is not None:
                    self._loop.run_coroutine(self.adapter.open_interface(0, 'streaming'))

                # Reenable tracing interface if that was open before as well
                if self._traces is not None:
                    self._loop.run_coroutine(self.adapter.open_interface(0, 'tracing'))
        except HardwareError as exc:
            self._logger.exception("Error reconnecting to device after an unexpected disconnect")
            raise HardwareError("Device disconnected unexpectedly and we could not reconnect", reconnect_error=exc) from exc
9121
def closed(self, reason):
        """"""
        self.client.remove_connection(self)
        self.protocol.connection_lost(reason)
        if not isinstance(reason, ConnectionClosed):
            logger.warn("connection closed, reason {}".format(reason))
        else:
            logger.info("connection closed")
1252347
def on_disconnect(client):
    
    print "-- Lost connection to %s" % client.addrport()
    CLIENT_LIST.remove(client)
    broadcast('%s leaves the conversation.\n' % client.addrport() )
594059
protected void reconnect(Throwable cause) {
		disconnect();
		logger.info("Trying to reconnect...");
		scheduler.schedule(this::connect, 5, TimeUnit.SECONDS);
	}
536200
def reconnect(self):
        """"""
        parsed = urlparse.urlparse(self.amqp_url)
        port = parsed.port or 5672
        self.connection = amqp.Connection(host="%s:%s" % (parsed.hostname, port),
                                          userid=parsed.username or 'guest',
                                          password=parsed.password or 'guest',
                                          virtual_host=unquote(
                                              parsed.path.lstrip('/') or '%2F'))
        self.channel = self.connection.channel()
        try:
            self.channel.queue_declare(self.name)
        except amqp.exceptions.PreconditionFailed:
            pass
689014
def _ensure_connection(self):
        """"""
        conn = self.connect()
        if conn.recycle and conn.recycle < time.time():
            logger.debug('Client session expired after %is. Recycling.', self._recycle)
            self.close()
            conn = self.connect()
        return conn
1154213
def _call_connection_lost_and_clean_up(self, exc):
        

        self._state = _State.CLOSED
        try:
            self._protocol.connection_lost(exc)
        finally:
            self._rawsock.close()
            if self._tls_conn is not None:
                self._tls_conn.set_app_data(None)
                self._tls_conn = None
            self._rawsock = None
            self._protocol = None
            self._loop = None
276891
def disconnect(self):
        """"""

        if not self.connected:
            raise HardwareError("Cannot disconnect when we are not connected")

        # Close the streaming and tracing interfaces when we disconnect
        self._reports = None
        self._traces = None

        self._loop.run_coroutine(self.adapter.disconnect(0))
        self.connected = False
        self.connection_interrupted = False
        self.connection_string = None