/** {@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} */ 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); }