protected function createServer($endpoint, $config = [])
    {
        if (stripos($endpoint, 'unix://') !== false)
        {
            if ($endpoint[7] === DIRECTORY_SEPARATOR)
            {
                $path = substr($endpoint, 7);
            }
            else
            {
                $path = getcwd() . DIRECTORY_SEPARATOR . substr($endpoint, 7);
                $endpoint = 'unix://' . $path;
            }

            if (file_exists($path))
            {
                unlink($path);
            }
        }

        $ssl = $this->config['ssl'];
        $name = $this->config['ssl_name'];
        $verifySign = $this->config['ssl_verify_sign'];
        $verifyPeer = $this->config['ssl_verify_peer'];
        $verifyDepth = $this->config['ssl_verify_depth'];

        $backlog = (int) (isset($config['backlog']) ? $config['backlog'] : self::DEFAULT_BACKLOG);
        $reuseaddr = (bool) (isset($config['reuseaddr']) ? $config['reuseaddr'] : false);
        $reuseport = (bool) (isset($config['reuseport']) ? $config['reuseport'] : false);

        $context = [];
        $context['socket'] = [
            'bindto' => $endpoint,
            'backlog' => $backlog,
            'ipv6_v6only' => true,
            'so_reuseaddr' => $reuseaddr,
            'so_reuseport' => $reuseport,
        ];
        $context['ssl'] = [
            'allow_self_signed' => !$verifySign,
            'verify_peer' => $verifyPeer,
            'verify_peer_name' => $verifyPeer,
            'verify_depth' => $verifyDepth,
            'disable_compression' => true,
            'SNI_enabled' => $name !== '',
            'SNI_server_name' => $name,
            'peer_name' => $name,
        ];

        if ($ssl && isset($config['ssl_cert']))
        {
            $context['ssl']['local_cert'] = $config['ssl_cert'];
        }

        if ($ssl && isset($config['ssl_key']))
        {
            $context['ssl']['local_pk'] = $config['ssl_key'];
        }

        if ($ssl && isset($config['ssl_secret']))
        {
            $context['ssl']['passphrase'] = $config['ssl_secret'];
        }

        $bitmask = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;

        $context = stream_context_create($context);

        // Error reporting suppressed since stream_socket_server() emits an E_WARNING on failure.
        $socket = @stream_socket_server(
            $endpoint,
            $errno,
            $errstr,
            $bitmask,
            $context
        );

        if (!$socket || $errno > 0)
        {
            throw new LogicException(
                sprintf('Could not bind socket [%s] because of error [%d; %s]', $endpoint, $errno, $errstr)
            );
        }

        return $socket;
    }