/** * Accepts incoming connections as they are made. */ private function accept(SocketServer $server) : Generator { yield from log()->log(Log::INFO, 'NNTP server listening on %s:%d', $server->getAddress(), $server->getPort()); while ($server->isOpen()) { // Wait for a client to connect. $socket = (yield from $server->accept()); // Handle the client in a separate coroutine. $coroutine = new Coroutine($this->handleClient($socket)); $coroutine->done(); } }
/** * @coroutine * * @param \Icicle\Socket\Server\Server $server * @param int $cryptoMethod * @param float $timeout * @param bool $allowPersistent * * @return \Generator */ private function accept(SocketServer $server, int $cryptoMethod, float $timeout, bool $allowPersistent) : \Generator { yield from $this->log->log(Log::INFO, 'HTTP server listening on %s:%d', $server->getAddress(), $server->getPort()); while ($server->isOpen()) { try { $coroutine = new Coroutine($this->process(yield from $server->accept(), $cryptoMethod, $timeout, $allowPersistent)); $coroutine->done(null, $this->onError); } catch (Throwable $exception) { if ($this->isOpen()) { throw $exception; } } } }