/**
  * @param Event $event
  * @param ClientInterface $client
  * @param ServerInterface $server
  * @return callable
  */
 public function __invoke(Event $event, ClientInterface $client, ServerInterface $server)
 {
     /** @var RequestHandlerInterface $requestHandler */
     $requestHandler = $this->getServiceManager()->get('RequestHandler', [$this->getServiceManager()]);
     $callbackHandler = $client->on(['data'], $requestHandler);
     $requestHandler->setCallbackHandler($callbackHandler);
     $requestHandler->on(['request'], $this->getCallback());
     $this->callPlugin('RequestHandler', [$requestHandler]);
     return $requestHandler;
 }
Ejemplo n.º 2
0
 /**
  * Connects a client to the socket
  *
  * @param ClientInterface $client
  * @param callable $callback
  * @return SocketInterface
  */
 public function connect(ClientInterface $client, callable $callback)
 {
     $internalCallback = function ($resource, $status) use($callback, $client) {
         if (!$status) {
             $client->emit(new Event('error'), [$resource, new ConnectionError('Could not open connection.', $status)]);
             return;
         }
         $client->on(['data'], $callback);
     };
     \uv_tcp_connect($client->getBackend(), $this->getBackend(), $internalCallback);
     return $this;
 }