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