예제 #1
0
 /**
  * @return int
  */
 public function receivePacket($bufferLength = 0)
 {
     if (!$this->channel->socket()->select(1)) {
         throw new TimeoutException();
     }
     if ($bufferLength == 0) {
         $this->buffer->clear();
     } else {
         $this->buffer = ByteBuffer::allocate($bufferLength);
     }
     $this->channel->read($this->buffer);
     $bytesRead = $this->buffer->position();
     $this->buffer->rewind();
     $this->buffer->limit($bytesRead);
     return $bytesRead;
 }
 /**
  * @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;
 }