/** {@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(); } }
/** {@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); } } }
/** {@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); }
/** * 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(); }
/** * Call next event handler * * @param Event $event Event object * * @return void */ private function callNextHandler(Event $event) { if ($this->next) { $this->next->invokeEvent($event); } }
/** {@inheritdoc} */ public function invokeEvent(Event $event) { if ($this->handlers) { $this->handlers->invokeEvent($event); } }