コード例 #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();
     }
 }
コード例 #2
0
 /** {@inheritdoc} */
 public function invokeEvent(Event $event)
 {
     if ($this->handler) {
         $this->handler->invokeEvent($event);
     }
     if ($event->getType() === EventType::FINALIZE) {
         $bag = $event->getExecutor()->socketBag();
         $socket = $event->getSocket();
         if ($bag->hasSocket($socket)) {
             $bag->removeSocket($socket);
         }
     }
 }
コード例 #3
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);
 }
コード例 #4
0
 /**
  * Handle OOB data
  *
  * @param RequestDescriptor        $descriptor Request descriptor
  * @param RequestExecutorInterface $executor Executor, processing operation
  * @param EventHandlerInterface    $eventHandler Event handler for this operation
  *
  * @return OperationInterface|null Operation to return to user or null to continue normal processing
  */
 private function handleOobData(RequestDescriptor $descriptor, RequestExecutorInterface $executor, EventHandlerInterface $eventHandler)
 {
     if (!$descriptor->hasState(RequestDescriptor::RDS_OOB)) {
         return null;
     }
     $descriptor->clearState(RequestDescriptor::RDS_OOB);
     $picker = new RawFramePicker();
     $socket = $descriptor->getSocket();
     $meta = $descriptor->getMetadata();
     $frame = $socket->read($picker, true);
     $event = new ReadEvent($executor, $socket, $meta[RequestExecutorInterface::META_USER_CONTEXT], $frame, true);
     $eventHandler->invokeEvent($event);
     return $event->getNextOperation();
 }
コード例 #5
0
 /**
  * Call next event handler
  *
  * @param Event $event Event object
  *
  * @return void
  */
 private function callNextHandler(Event $event)
 {
     if ($this->next) {
         $this->next->invokeEvent($event);
     }
 }
コード例 #6
0
 /** {@inheritdoc} */
 public function invokeEvent(Event $event)
 {
     if ($this->handlers) {
         $this->handlers->invokeEvent($event);
     }
 }