/** * {@inheritdoc} */ public function listen(callable $action) : Awaitable { return new Coroutine(function () use($action) { $factory = clone $this->factory; $factory->setTcpNoDelay(true); if ($factory->isEncrypted() && Socket::isAlpnSupported()) { $protocols = []; foreach ($this->drivers as $driver) { foreach ($driver->getProtocols() as $protocol) { $protocols[$protocol] = true; } } $factory->setOption('ssl', 'alpn_protocols', implode(',', \array_keys($protocols))); } $this->server = (yield $factory->createSocketServer()); $port = $this->server->getPort(); $peer = $this->server->getAddress() . ($port ? ':' . $port : ''); $context = new HttpDriverContext($peer, $factory->getPeerName(), $factory->isEncrypted(), $this->middlewares, $this->responders, $this->proxySettings); return new HttpServer($this, $this->server, new Coroutine($this->runServer($context, $action))); }); }
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'); }