Called on event 'connection'
@param AuthClient $connection
979072
public function onConnection(AuthClient $connection)
    {
        //bubble the events up
        $connection->on('login_success', function(AuthClient $client, DisconnectPacket $packet) {
            $this->emit('login_success', [$client->getUsername(), $client->getUUID(), $packet]);
        });

        $connection->on('status_request', function(StatusResponsePacket $packet) {
            $this->emit('status_request', [$packet]);
        });

        $connection->on('close', function() use (&$connection) {
            $amount = count($this->clients);
            for($i = 0; $i<$amount; $i++) {
                /** @var $checkclient AuthClient */
                $checkclient = $this->clients[$i];
                //if we found our connection
                if($checkclient === $connection) {
                    //remove from array and reset the keys
                    unset($this->clients[$i]);
                    $this->clients = array_values($this->clients);
                    echo "A client disconnected. Now there are total ". ($amount - 1) . " clients.\n";
                    $this->emit('disconnect', []);
                    return;
                }
            }
        });

        //if there is an error with the connection echo the error and end the connection
        $connection->on('error', function($error, Connection $connection) {
            echo "ERROR: $error\n";
            $connection->end();
        });

        //add the connection to the list of tracked connections
        $this->clients[] = $connection;

        //echo how many are now online
        $count = count($this->clients);
        echo "New client conected: {$connection->getRemoteAddress()}. Clients online: $count.\n";
    }
952756
private function sendMessageEnvelope(WindowsConnection $connection, WindowsMessageEnvelope $messageEnvelope)
    {
        $response = $connection->sendAndReceive($messageEnvelope->getMessage());
        $messageEnvelope->setResponse($response);
        if ($response->isSuccess()) {
            $messageEnvelope->setState(MessageEnvelope::SUCCESS);
        } else {
            $messageEnvelope->setState(MessageEnvelope::FAILED);
        }
    }
588124
public function onGatewayClose($connection)
    {
        $addr = $connection->remoteAddress;
        unset($this->gatewayConnections[$addr], $this->_connectingGatewayAddresses[$addr]);
        if (isset($this->_gatewayAddresses[$addr]) && !isset($this->_waitingConnectGatewayAddresses[$addr])) {
            Timer::add(1, array($this, 'tryToConnectGateway'), array($addr), false);
            $this->_waitingConnectGatewayAddresses[$addr] = $addr;
        }
    }
40916
protected function checkSlave(Connection $connection)
    {
        $paused = 0;

        while (($lag = $this->getLag($connection)) > $this->options['max_lag']) {
            $this->paused = true;
            $for = $this->options['pause_lag'];

            $this->logger->notice('Chunk detected lag of {lag} on {database}, pausing for {for}', [
                'lag'      => $lag,
                'database' => sprintf('%s/%s', $connection->getHost(), $connection->getDatabase()),
                'for'      => $for
            ]);

            usleep($for);
            $paused += $for;

            if ($paused > $this->options['max_pause_lag']) {
                if ($this->options['continue_lag']) {
                    break;
                } else {
                    throw new RuntimeException('Slave lag did not recover after processing chunk. Aborting.');
                }
            }
        }
    }
53313
protected function checkRequestsPerMinute(Connection $connection)
    {
        $id = $connection->getId();

        if (!isset($this->requests[$id])) {
            $this->requests[$id] = [];
        }

        // Add current token
        $this->requests[$id][] = time();

        // Expire old tokens
        while (reset($this->requests[$id]) < time() - 60) {
            array_shift($this->requests[$id]);
        }

        if (count($this->requests[$id]) > $this->options['requests_per_minute']) {
            $this->limit($connection, 'Requests per minute');
        }
    }
317038
protected function createConnection($connection)
    {
        // Load config connection
        $config = Arr::get($this->config, 'connections.' . $connection);
        if (is_null($config)) {
            throw new \InvalidArgumentException("config connection [$connection] not found.");
        }

        $driver = Arr::get($config, 'driver');
        if (is_null($driver)) {
            throw new \InvalidArgumentException("driver connection [$connection] not information.");
        }

        // We'll check to see if a creator method exists for the given connection. If not we
        // will check for a custom connection creator, which allows developers to create
        // connections using their own customized connection creator Closure to create it.
        if (isset($this->customCreators[$driver])) {
            return $this->callCustomCreator($driver, $config);
        } else {
            $method = 'create' . Str::studly($driver) . 'Driver';

            if (method_exists($this, $method)) {
                return $this->$method($config);
            }
        }
        throw new \InvalidArgumentException("driver [$driver] connection [$connection] not supported.");
    }
24715
public function setConnect(array $connect): void
    {
        $this->connect = array_merge($this->connect, $connect);
        $this->checkConnect();
    }
201622
public function connection($connection = null)
    {
        $connection = $connection ?: $this->getDefaultConnection();

        if (is_null($connection)) {
            throw new \InvalidArgumentException(sprintf('Unable to resolve NULL connection for [%s].', get_called_class()));
        }

        // If the given connection has not been created before, we will create the instances
        // here and cache it so we can return it next time very quickly. If there is
        // already a connection created by this name, we'll just return that instance.
        if (! isset($this->connections[$connection])) {
            $this->connections[$connection] = $this->createConnection($connection);
        }

        return $this->connections[$connection];
    }
760656
public function onMessage($connection, $data)
    {
        $uri  = parse_url($_SERVER['REQUEST_URI']);
        $path = isset($uri['path']) ? $uri['path'] : '/';

        $file = $this->root . $path;

        if (!is_file($file)) {
            $this->app->worker($connection, $data);
        } else {
            $this->sendFile($connection, $file);
        }
    }
620726
public function beforeQuery(Event $event, $connection)
    {
        $this->profiler->startProfile($connection->getSQLStatement(), $connection->getSqlVariables(), $connection->getSQLBindTypes());
    }
1302758
protected function setOutput(Connection $connection)
	{
		$output = php_sapi_name() == 'cli' ? new ConsoleOutput : new NullOutput;

		$connection->setOutput($output);
	}
436224
public function addConnection(string $connectionName, \PDO $connection): void
    {
        $this->connections[$connectionName] = $connection;
    }
701724
function(connection) {
      var t = this;
      log.info('removeConnection', 'Conn_' + connection.id);
      connection.disconnect('connection_removed');
      t.connections.remove(connection);
      t.trigger('connection:remove', connection);
    }
1361932
public function sanitizeConnection($connection = null, $server = null)
    {
        if (!$connection) {
            return $this->connections->getCurrentConnectionKey();
        }

        return $connection instanceof ConnectionKey ? $connection : $this->createConnectionKey($connection, $server);
    }
1294344
public function onWorkerConnect($connection)
    {
        $connection->maxSendBufferSize = $this->sendToWorkerBufferSize;
        $connection->authorized = $this->secretKey ? false : true;
    }
1306659
public function connection($connection = null)
    {
        $type = $connection ?? $this->defaultConnection;

        if (!isset($this->connection[$type]))
        {
            $slice = $this->slice->getSlice($type);

            $key     = $slice->getRequired('adapter');
            $adapter = $this->adapters[$key];

            $this->adapterProviders[$type] = new $adapter();

            $this->adapterProviders[$type]->setHost($slice->getData('host'));
            $this->adapterProviders[$type]->setPort($slice->getData('port'));

            if (method_exists($this->adapterProviders[$type], 'setPath'))
            {
                $this->adapterProviders[$type]->setPath($slice->getData('path'));
            }

            $this->adapterProviders[$type]->setDbName($slice->getData('database'));

            $this->adapterProviders[$type]->setConnection($this);

            $this->adapterProviders[$type]->setPDOClass(Connection::class);

            $options = [
                Connection::ATTR_DEFAULT_FETCH_MODE => Connection::FETCH_ASSOC,
                //Connection::ATTR_EMULATE_PREPARES   => true,
                //Connection::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
                //Connection::ATTR_PERSISTENT         => false,
                //Connection::MYSQL_ATTR_INIT_COMMAND       => 'SET NAMES utf8mb4'
            ];

            if ($this->adapterProviders[$type]->name() !== 'sqlite')
            {
                $options[Connection::ATTR_ERRMODE] = Connection::ERRMODE_EXCEPTION;
            }

            $this->connection[$type] = $this->adapterProviders[$type]->connection(
                $slice->getData('username'),
                $slice->getData('password'),
                $slice->getData('options', $options)
            );
        }

        return $this->connection[$type];
    }
1281556
public static function onClose($connection)
    {
        $connection->handshakeStep               = null;
        $connection->websocketCurrentFrameLength = 0;
        $connection->tmpWebsocketData            = '';
        $connection->websocketDataBuffer         = '';
        if (!empty($connection->websocketPingTimer)) {
            Timer::del($connection->websocketPingTimer);
            $connection->websocketPingTimer = null;
        }
    }