/** {@inheritdoc} */ protected function readRawDataIntoPicker(FramePickerInterface $picker, $isOutOfBand) { $size = self::SOCKET_BUFFER_SIZE; $resource = $this->socket->getStreamResource(); do { $data = stream_socket_recvfrom($resource, $size, STREAM_PEEK); if (strlen($data) < $size) { break; } $size += $size; } while (true); $data = stream_socket_recvfrom($resource, $size, 0, $actualRemoteAddress); return $picker->pickUpData($data, $actualRemoteAddress); }
/** * Read regular data * * @param FramePickerInterface $picker Picker to read data into * * @return string */ private function readRegularData(FramePickerInterface $picker) { // work-around https://bugs.php.net/bug.php?id=52602 $resource = $this->socket->getStreamResource(); $readContext = ['countCycles' => 0, 'dataBeforeIo' => $this->getDataInSocket(), 'isStreamDataEmpty' => false]; do { $data = fread($resource, self::SOCKET_BUFFER_SIZE); $this->throwNetworkSocketExceptionIf($data === false, 'Failed to read data.', true); $isDataEmpty = $data === ''; $result = $picker->pickUpData($data, $this->getRemoteAddress()); $readContext['countCycles'] += 1; $readContext['isStreamDataEmpty'] = $this->isReadDataActuallyEmpty($data); $this->readAttempts = $this->resolveReadAttempts($readContext, $this->readAttempts); } while (!$picker->isEof() && !$isDataEmpty); return $result; }
/** {@inheritdoc} */ protected function readRawDataIntoPicker(FramePickerInterface $picker, $isOutOfBand) { $data = $this->data; $this->data = ''; return $picker->pickUpData($data, $this->remoteAddress); }
/** * Read unhandled data if there is something from the previous operation * * @param FramePickerInterface $picker Frame picker to use * @param Context $context Socket context * @param bool $isOutOfBand Flag if it is out-of-band data * * @return bool Flag whether it is the end of the frame */ private function handleUnreadData(FramePickerInterface $picker, Context $context, $isOutOfBand) { $unhandledData = $context->getUnreadData($isOutOfBand); if ($unhandledData) { $context->setUnreadData($picker->pickUpData($unhandledData, $this->getRemoteAddress()), $isOutOfBand); } return $picker->isEof(); }