Creates a socket to communicate with the worker handler.

@param Socket $socket

@return null
328020
protected function createWorkerHandlerStream(Socket $socket)
    {
        $socket->setId('manager');
        $this->getPoller()->add($socket, ZMQ::POLL_IN);

        $that = $this;
        $this->workerHandlerStream = $socket->getStream();
        $this->workerHandlerStream->addListener(StreamInterface::MESSAGE, function (MessageEvent $event) use ($that) {
            if (null === $event->getProtocolMessage()) {
                $message = $event->getMessage();

                $that->getLogger()->error('Non-protocol message detected in worker-handler stream: '.$message);

                return;
            }

            $that->onWorkerHandlerMessage($event->getProtocolMessage());
        });
    }
252309
protected function getSocket($server)
    {
        if (isset($this->socket[$server])) {
            return $this->socket[$server];
        }

        $context = new ZMQContext();
        $socket = Socket::create($context, ZMQ::SOCKET_REQ, $this->logger);
        $socket->connect($server);

        $this->socket[$server] = $socket;

        return $socket;
    }
438251
public function connect()
    {
        $socket = $this->createSocket(
            $this->connection->getHostname(),
            $this->connection->getPort(),
            $this->throttle
        );

        $this->setSocket($socket);
    }
1371971
protected function getConnectionForClientSocket($socket): ?Connection
    {
        if (!isset($this->connections[$this->resourceId($socket)])) {
            return null;
        }
        return $this->connections[$this->resourceId($socket)];
    }
1049650
function close($socket) {
		if (isset($this->agents[(int)$socket]))
			unset($this->sockets[(int)$socket],$this->agents[(int)$socket]);
		stream_socket_shutdown($socket,STREAM_SHUT_WR);
		@fclose($socket);
	}
432048
protected function writeToSocket($socket, $message)
    {
        socket_sendto($socket, $message, strlen($message), 0, PAPERTRAIL_HOST, PAPERTRAIL_PORT);
    }
1241424
function connection(socket){
	this.socket = socket;
	if (!!this.options.encoding) socket.setEncoding(this.options.encoding);
	socket.on('data', this.emit.bind(this, 'data'));
	this.emit('connection', socket);
}
709905
def socket_worker(sock, msg_q):
    """"""
    _LOGGER.debug("Starting Socket Thread.")
    while True:
        try:
            data, addr = sock.recvfrom(1024)    # buffer size is 1024 bytes
        except OSError as err:
            _LOGGER.error(err)
        else:
            _LOGGER.debug("received message: %s from %s", data, addr)
            msg_q.put(data)
        time.sleep(0.2)
1348120
private static function listenOnBoundSocket(
        $socket,
        Socket\ServerListenContext $listenContext,
        Socket\ServerTlsContext $tlsContext = null
    ): Server {
        if ($tlsContext) {
            $context = \array_merge(
                $listenContext->toStreamContextArray(),
                $tlsContext->toStreamContextArray()
            );
        } else {
            $context = $listenContext->toStreamContextArray();
        }

        \socket_listen($socket, $context["socket"]["backlog"] ?? 0);

        /** @var resource $stream */
        /** @noinspection PhpVoidFunctionResultUsedInspection */
        $stream = \socket_export_stream($socket);
        \stream_context_set_option($stream, $context); // put eventual options like ssl back (per worker)

        return new Server($stream);
    }
385171
public function socket($request = null)
    {
        if (! $request && ! $this->container->bound('request')) {
            return null;
        }

        $request = $request ?: $this->container['request'];

        return $request->header('X-Socket-ID');
    }
86547
static public function getFromSocket($socket) {
        try {
            $version = $socket->getVersion();
        } catch (Mage_Core_Exception $e) {
            Mage::getSingleton('core/session')
                ->addError('Error determining Varnish version: '.
                    $e->getMessage());
            return null;
        }
        switch ($version) {
            case '4.0':
            case '4.1':
                return Mage::getModel(
                    'turpentine/varnish_configurator_version4',
                    array('socket' => $socket) );

            case '3.0':
                return Mage::getModel(
                    'turpentine/varnish_configurator_version3',
                        array('socket' => $socket) );
            case '2.1':
                return Mage::getModel(
                    'turpentine/varnish_configurator_version2',
                        array('socket' => $socket) );
            default:
                Mage::throwException('Unsupported Varnish version');
        }
    }
956423
protected function createReplySocket()
    {
        $replyContext = new \ZMQContext;
        $this->replySocket = $replyContext->getSocket(\ZMQ::SOCKET_REQ);
        $this->replySocket->connect($this->config['sockets']['worker_reply']);
    }
1181056
protected function processMasterSocket(): void
    {
        $new = null;

        try {
            $new = $this->socket->accept();
        } catch (Exception $e) {
            $this->logger->error('Socket error: {exception}', [
                'exception' => $e,
            ]);
            return;
        }

        $connection = $this->createConnection($new);
        $this->server->notify(Server::EVENT_SOCKET_CONNECT, [$new, $connection]);
    }
400231
def add_socket(self, socket):
        
        if socket not in self._sockets:
            self._sockets.add(socket)
            socket.on_closed.connect(self.remove_socket)
1202404
protected function getStream($socket)
    {
        if (class_exists(DuplexResourceStream::class)) {
            return new DuplexResourceStream($socket, $this->getLoop());
        }

        return new Stream($socket, $this->getLoop());
    }
505257
public function acceptUdp($socket){
        $peer = null;
        $message = stream_socket_recvfrom($socket , $this->max_udp_packet_size, 0, $peer);
        
        //thundering herd EAGAIN (Resource temporarily unavailable)
        if(!$peer || $message === false || $message === ''){
            return false;
        }
        
        $local = stream_socket_get_name($socket, false);
        
        $event = new UdpMessageEvent(['message'=>$message, 'socket'=>$socket]);
        
        if($this->parser) {
            $message = call_user_func([$this->parser, 'decode'], $message, null);
        }
        
        $event->local = $local;
        $event->peer = $peer;
        
        $this->trigger(Server::ON_UDP_PACKET, $event);
    }
340339
protected function configureSocket()
    {
        $class = $this->options['socket_class'];
        $options = $this->options['socket_options'];
        $this->socket = new $class($this->uri, $options);
    }