/** {@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(); } }
/** * Check whether socket waiting is finished * * @param RequestDescriptor $descriptor Request descriptor to test * * @return bool True if delay is complete, false otherwise */ private function checkDelayIsFinished(RequestDescriptor $descriptor) { /** @var DelayedOperation $socketOperation */ $socketOperation = $descriptor->getOperation(); $arguments = $socketOperation->getArguments(); array_unshift($arguments, $descriptor->getSocket(), $this->executor); return !call_user_func_array($socketOperation->getCallable(), $arguments); }
/** {@inheritdoc} */ protected function handleOperation(RequestDescriptor $descriptor, RequestExecutorInterface $executor, EventHandlerInterface $eventHandler) { $operation = $descriptor->getOperation(); $socket = $descriptor->getSocket(); /** @var SslHandshakeOperation $operation */ $resource = $descriptor->getSocket()->getStreamResource(); $result = stream_socket_enable_crypto($resource, true, $operation->getCipher()); if ($result === true) { return $operation->getNextOperation(); } elseif ($result === false) { throw new SslHandshakeException($socket, 'SSL handshake failed.'); } return $operation; }
/** {@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); }
/** * Fill next operation in given object and return flag indicating whether operation is required * * @param RequestDescriptor $requestDescriptor Request descriptor object * @param OperationInterface $nextOperation Next operation object * * @return bool True if given operation is complete */ private function resolveNextOperation(RequestDescriptor $requestDescriptor, OperationInterface $nextOperation) { if ($nextOperation instanceof NullOperation) { $requestDescriptor->setOperation($nextOperation); return true; } if ($requestDescriptor->getOperation() === $nextOperation) { return false; } $requestDescriptor->setOperation($nextOperation); $requestDescriptor->setMetadata([RequestExecutorInterface::META_LAST_IO_START_TIME => null]); return false; }
/** * Check if this socket can be a zombie * * @param RequestDescriptor $descriptor Descriptor object * * @return bool */ private function isZombieCandidate(RequestDescriptor $descriptor) { $metadata = $descriptor->getMetadata(); if ($metadata[RequestExecutorInterface::META_REQUEST_COMPLETE]) { return false; } $operation = $descriptor->getOperation(); return $operation instanceof NullOperation || $operation instanceof ReadOperation && $operation->getFramePicker() instanceof EmptyFramePicker; }
/** {@inheritdoc} */ public function isSatisfiedBy(RequestDescriptor $requestDescriptor) { return $requestDescriptor->getSocket() instanceof UdpClientSocket && $requestDescriptor->getOperation() instanceof ReadOperation; }