コード例 #1
0
 /**
  * Perform data writing to socket and return suitable next socket operation
  *
  * @param WriteOperation     $operation Current write operation instance
  * @param SocketInterface    $socket Socket object
  * @param OperationInterface $nextOperation Desirable next operation
  *
  * @return OperationInterface Actual next operation
  */
 private function writeDataToSocket(WriteOperation $operation, SocketInterface $socket, OperationInterface $nextOperation = null)
 {
     $result = $nextOperation;
     $extractNextOperation = true;
     if ($operation->hasData()) {
         $data = $operation->getData();
         $length = strlen($data);
         $written = $socket->write($data, $operation->isOutOfBand());
         if ($length !== $written) {
             $extractNextOperation = false;
             $operation = $this->makeInProgressWriteOperation($operation, $nextOperation);
             $operation->setData(substr($operation->getData(), $written));
             $result = $operation;
         }
     }
     if ($extractNextOperation && $operation instanceof InProgressWriteOperation) {
         /** @var InProgressWriteOperation $operation */
         $result = $operation->getNextOperation();
     }
     return $result;
 }
コード例 #2
0
 /**
  * Check whether given socket should be disconnected
  *
  * @param SocketInterface $socket Socket object
  *
  * @return bool
  */
 private function isDisconnectRequired(SocketInterface $socket)
 {
     return $socket instanceof PersistentClientSocket && (feof($socket->getStreamResource()) !== false || !stream_socket_get_name($socket->getStreamResource(), true)) || !$socket instanceof PersistentClientSocket;
 }
コード例 #3
0
 /** {@inheritdoc} */
 public function getStreamResource()
 {
     return $this->socket->getStreamResource();
 }