Example #1
0
 public function read($callable, $num = false)
 {
     if (is_callable($callable) && $num) {
         return $this->readIterable($callable, $num);
     } else {
         $num = $callable;
     }
     $buffer = ByteBuffer::create();
     $count = 0;
     while ($count < $num) {
         $byte = fgetc($this->socket);
         $buffer->push($byte);
         $count++;
     }
     $this->count += $count;
     return $buffer;
 }
Example #2
0
 protected function generateMask()
 {
     return ByteBuffer::create(array(rand(0, 255), rand(0, 255), rand(0, 255), rand(0, 255)));
 }
Example #3
0
 /**
  * parseNumberToCountBuffer function.
  * 
  * @access public
  * @static
  * @param mixed $num
  * @return void
  */
 public static function parseNumberToCountBuffer($count, $mask = true)
 {
     if ($count < 125) {
         if ($mask) {
             $count += 128;
         }
         $count = ByteBuffer::create(array((int) $count));
     } else {
         if ($count > 125 && $count < self::DOUBLE_BYTE_LENGTH) {
             $count = ByteBuffer::parseNumberToBuffer($count);
             $extraByte = $mask ? self::DOUBLE_BYTE : self::DOUBLE_BYTE - 128;
             $count->unshift($extraByte);
         } else {
             $count = ByteBuffer::parseNumberToBuffer($count);
             $extraByte = $mask ? self::QUAD_BYTE : self::QUAD_BYTE - 128;
             $count->unshift($extraByte);
         }
     }
     return $count;
 }