コード例 #1
0
 public function read(ByteBuffer $destinationBuffer)
 {
     $length = $destinationBuffer->remaining();
     $data = $this->socket->recv($length);
     $destinationBuffer->put($data);
     return strlen($data);
 }
コード例 #2
0
 /**
  * @return int
  */
 public function receivePacket($bufferLength = 0)
 {
     if (!$this->socket->select(self::$timeout)) {
         throw new TimeoutException();
     }
     if ($bufferLength == 0) {
         $this->buffer->clear();
     } else {
         $this->buffer = ByteBuffer::allocate($bufferLength);
     }
     $data = $this->socket->recv($this->buffer->remaining());
     $this->buffer->put($data);
     $bytesRead = $this->buffer->position();
     $this->buffer->rewind();
     $this->buffer->limit($bytesRead);
     return $bytesRead;
 }