public function createSocketFactory() : SocketFactory { $factory = new SocketFactory(\sprintf('%s:%s', $this->address, $this->port), $this->protocol); $factory->setPeerName($this->getPeerName()); return $factory; }
protected function connectSocket(Uri $uri) : Awaitable { $host = $uri->getHost(); if (Address::isResolved($host)) { $factory = new SocketFactory(new Address($host) . ':' . $uri->getPort(), 'tcp'); } else { $factory = new SocketFactory($uri->getHostWithPort(true), 'tcp'); } $factory->setTcpNoDelay(true); if ($this->protocols && Socket::isAlpnSupported()) { $factory->setOption('ssl', 'alpn_protocols', \implode(',', $this->protocols)); } return $factory->createSocketStream(5, $uri->getScheme() === 'https'); }
\ob_start(function () { }); \error_reporting(-1); \ini_set('display_errors', false); \set_error_handler(function ($severity, $message) { if ($severity & \error_reporting()) { throw new \Error($message, $severity); } }); require_once $_SERVER['autoloader']; $exitCode = 1; Loop::execute(function () use(&$exitCode) { new Coroutine(function () use(&$exitCode) { $id = (string) $_SERVER['id']; list($protocol, $peer) = \explode('://', (string) $_SERVER['ipc'], 2); $factory = new SocketFactory($peer, $protocol); $socket = (yield $factory->createSocketStream(2)); $transmitter = new SocketTransmitter($socket); try { yield from $transmitter->send(['id' => $id], SocketTransmitter::TYPE_HANDSHAKE); while (true) { list($type, $payload) = (yield from $transmitter->receive()); if ($type === SocketTransmitter::TYPE_EXIT) { yield from $transmitter->send($payload, $type); $socket->close(); $exitCode = 0; break; } try { if (isset($payload['func'])) { if (\substr($payload['func'], 0, 1) === '@') {