read binary data from socket

@param   int  $length  length of data to read
@return  string  data read from socket
@throws  \stubbles\peer\ConnectionFailure
@throws  \stubbles\peer\Timeout
979454
public function readBinary(int $length = 1024): string
    {
        $data = fread($this->resource, $length);
        if (false === $data) {
            if (stream_get_meta_data($this->resource)['timed_out']) {
                throw new Timeout(
                        'Reading of ' . $length . ' bytes failed: timeout of '
                        . $this->timeout . ' seconds exceeded'
                );
            }

            throw new ConnectionFailure(
                    'Reading of ' . $length . ' bytes failed.'
            );
        }

        return $data;
    }
838131
public function read($length)
    {
        $buffer = '';
        $total = count($this->streams) - 1;
        $remaining = $length;

        while ($remaining > 0) {
            // Progress to the next stream if needed.
            if ($this->streams[$this->current]->eof()) {
                if ($this->current == $total) {
                    break;
                }
                $this->current++;
            }
            $buffer .= $this->streams[$this->current]->read($remaining);
            $remaining = $length - strlen($buffer);
        }

        $this->pos += strlen($buffer);

        return $buffer;
    }
638385
public function readHex(int $length)
    {
        $value = Reader::high($this->bytes, 0, $length * 2);

        $this->skip($length);

        return $value;
    }
9020
public function &readBuffer($length) {

            if ($length+$this->cursor > strlen($this->rawData)) {
                throw new Exception('Buffer underrun at position: '. $this->cursor . '. Trying to fetch '. $length . ' bytes');
                return false;
            }
            $data = substr($this->rawData,$this->cursor,$length);
            $this->cursor+=$length;
            return $data;

        }
212971
private static function read($fd, $length)
    {
        $bytes = fread($fd, $length);
        if (false === $bytes) {
            return false;
        }

        return $bytes;
    }
119774
public function read(int $length = 8192): string
    {
        $bytes           = substr($this->buffer, $this->position, $length);
        $this->position += strlen($bytes);
        return $bytes;
    }
38153
protected function read($length) {
		if ($this->length < $length) {
			throw new \Exception('Reading while at end of stream');
		}
		$output = substr($this->data, 0, $length);
		$this->data = substr($this->data, $length);
		$this->length -= $length;
		return $output;
	}
1280451
protected function readbytes($length)
    {
        if ($this->comptype === Archive::COMPRESS_GZIP) {
            return @gzread($this->fh, $length);
        } elseif ($this->comptype === Archive::COMPRESS_BZIP) {
            return @bzread($this->fh, $length);
        } else {
            return @fread($this->fh, $length);
        }
    }
1025942
public function read($length)
    {
        $index = 0;
        $contents = '';
        while ($this->iterator->valid() && $index < $length) {
            if ($this->stringify !== null) {
                $contents .= $this->stringify->call($this, $this->iterator->current());
            } else {
                $contents .= $this->iterator->current();
            }

            $this->iterator->next();
            ++$this->position;
            ++$index;
        }

        return $contents;
    }
201580
public function read($length = 4096)
  {
    $this->connect();
    $this->waitForReadyRead();

    $data = @fread($this->stream, $length);

    TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data);

    if($data === FALSE)
    {
      throw new TeamSpeak3_Transport_Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost");
    }

    return new TeamSpeak3_Helper_String($data);
  }
236247
private function read($bytes)
    {
        $buffer = call_user_func($this->reader, min($bytes, self::READ_BUFFER_LENGTH));
        if ($buffer === false || $buffer === '') {
            throw new ConnectionException('Error while reading buffered string from client');
        }
        return $buffer;
    }
1319845
public function read($length)
	{
		$read = 0;
		$parts = array();

		while ($read < $length && !$this->_wrapper()->feof($this->_socket))
		{
			$data = $this->_wrapper()
				->fread($this->_socket, $length - $read);

			if ($data === false)
			{
				throw new Pheanstalk_Exception_SocketException('fread() returned false');
			}

			$read += strlen($data);
			$parts []= $data;
		}

		return implode($parts);
	}
904836
public function read($length)
    {
        if ($this->deadline) {
            stream_set_timeout($this->socket, max($this->deadline - time(), 1));
        }

        // Note: For correct behaviour, $length should be the same at the
        // PHP stream chunk size. For all PHP < 5.4 this is 8192. Other values
        // will cause PHP's internal stream buffer to be used and break
        // stream_select() semantics. See https://bugs.php.net/bug.php?id=52602
        $data = fread($this->socket, $length);

        $this->checkTimeout();
        return $data;
    }
940471
public function Read( $Length = 1400 )
		{
			$Buffer = new Buffer( );
			$Buffer->Set( FRead( $this->Socket, $Length ) );
			
			$this->ReadInternal( $Buffer, $Length, [ $this, 'Sherlock' ] );
			
			return $Buffer;
		}
171641
public function read($length = null)
    {
        $this->_ensureReadable();
        $length = $this->_bufferSize($length);
        if ($length <= 0) {
            return '';
        }
        $result = fread($this->_resource, $length);
        return $result === false ? '' : $result;
    }
727853
public static function read($socket)
    {
        $header = '';
        do {
            $buf = socket_read($socket, 12 - self::stringLength($header));
            $header .= $buf;
        } while ($buf !== false &&
                 $buf !== '' && self::stringLength($header) < 12);

        if ($buf === '') {
            throw new Exception('Connection was reset');
        }

        if (self::stringLength($header) == 0) {
            return array();
        }
        $resp = @unpack('a4magic/Ntype/Nlen', $header);

        if (!count($resp) == 3) {
            throw new Exception('Received an invalid response');
        }

        if (!isset(self::$magic[$resp['type']])) {
            throw new Exception(
                'Invalid response magic returned: ' . $resp['type']
            );
        }

        $return = array();
        if ($resp['len'] > 0) {
            $data = '';
            while (self::stringLength($data) < $resp['len']) {
                $data .= socket_read($socket, $resp['len'] - self::stringLength($data));
            }

            $d = explode("\x00", $data);
            foreach (self::$magic[$resp['type']][1] as $i => $a) {
                $return[$a] = $d[$i];
            }
        }

        $function = self::$magic[$resp['type']][0];
        if ($function == 'error') {
            if (!self::stringLength($return['err_text'])) {
                $return['err_text'] = 'Unknown error; see error code.';
            }

            throw new Exception(
                $return['err_text'], $return['err_code']
            );
        }

        return array('function' => self::$magic[$resp['type']][0],
                     'type' => $resp['type'],
                     'data' => $return, );
    }
492971
protected function _fread($length = 1)
    {
        $returnValue = substr($this->_data, $this->_position, $length);
        $this->_position += $length;
        return $returnValue;
    }