Exemplo n.º 1
0
 /** {@inheritdoc} */
 protected function handleOperation(RequestDescriptor $descriptor, RequestExecutorInterface $executor, EventHandlerInterface $eventHandler)
 {
     $operation = $descriptor->getOperation();
     $socket = $descriptor->getSocket();
     $meta = $executor->socketBag()->getSocketMetaData($socket);
     $context = $meta[RequestExecutorInterface::META_USER_CONTEXT];
     try {
         /** @var ReadOperation $operation */
         $response = $socket->read($operation->getFramePicker());
         switch (true) {
             case $response instanceof PartialFrame:
                 return $operation;
             case $response instanceof AcceptedFrame:
                 $event = new AcceptEvent($executor, $socket, $context, $response->getClientSocket(), $response->getRemoteAddress());
                 $eventHandler->invokeEvent($event);
                 return new ReadOperation();
             default:
                 $event = new ReadEvent($executor, $socket, $context, $response, false);
                 $eventHandler->invokeEvent($event);
                 return $event->getNextOperation();
         }
     } catch (AcceptException $e) {
         return new ReadOperation();
     }
 }
Exemplo n.º 2
0
 /** {@inheritdoc} */
 protected function handleOperation(RequestDescriptor $descriptor, RequestExecutorInterface $executor, EventHandlerInterface $eventHandler)
 {
     $operation = $descriptor->getOperation();
     $socket = $descriptor->getSocket();
     /** @var WriteOperation $operation */
     $fireEvent = !$operation instanceof InProgressWriteOperation;
     if ($fireEvent) {
         $meta = $executor->socketBag()->getSocketMetaData($socket);
         $event = new WriteEvent($operation, $executor, $socket, $meta[RequestExecutorInterface::META_USER_CONTEXT]);
         $eventHandler->invokeEvent($event);
         $nextOperation = $event->getNextOperation();
     } else {
         $nextOperation = $operation;
     }
     return $this->writeDataToSocket($operation, $socket, $nextOperation);
 }
Exemplo n.º 3
0
 /** {@inheritdoc} */
 public function removeSocket(SocketInterface $socket)
 {
     $key = $this->getOperationStorageKey($socket);
     if (!isset($this->items[$key])) {
         return;
     }
     $meta = $this->items[$key]->getMetadata();
     if (!$meta[RequestExecutorInterface::META_REQUEST_COMPLETE] && $this->executor->isExecuting()) {
         throw new \LogicException('Can not remove unprocessed socket during request processing.');
     }
     unset($this->items[$key]);
 }