Network\Socket::_connect PHP Метод

_connect() защищенный Метод

Establishes the socket connection.
protected _connect ( ) : void
Результат void
    protected function _connect()
    {
        if (null !== $this->_connection) {
            return;
        }
        $this->_connection = new Connection(socket_create($this->_options['domain'], $this->_options['type'], $this->_options['protocol']));
        // timeout
        socket_set_option($this->_connection->get_resource(), SOL_SOCKET, SO_RCVTIMEO, ['sec' => XPSPL_NETWORK_TIMEOUT_SECONDS, 'usec' => XPSPL_NETWORK_TIMEOUT_MICROSECONDS]);
        for ($i = 0; $i != 1000; $i++) {
            try {
                false === socket_bind($this->_connection->get_resource(), $this->_address, $this->_options['port']) ? throw_socket_error() : null;
                if (XPSPL_DEBUG) {
                    logger(XPSPL_DEBUG)->debug('Main connection established');
                }
                break;
            } catch (\RuntimeException $e) {
                if ($i >= 250) {
                    if (XPSPL_DEBUG) {
                        logger(XPSPL_DEBUG)->debug(sprintf('Could not connect %s', $e->getMessage()));
                    }
                    exit(1);
                } else {
                    if (XPSPL_DEBUG) {
                        logger(XPSPL_DEBUG)->debug('Reattempt connection in ' . log($i, 2) * 0.1 * 1000000 . 'us');
                    }
                    usleep(log($i, 2) * 0.1 * 1000000);
                }
            }
        }
        // listen
        socket_listen($this->_connection->get_resource());
        socket_set_nonblock($this->_connection->get_resource());
    }