Network\Connection::_read_buffer PHP Méthode

_read_buffer() public méthode

Reads the given length of data from the socket into the read buffer.
public _read_buffer ( integer $length = XPSPL_SOCKET_READ_LENGTH, integer $flags = MSG_DONTWAIT ) : string
$length integer Maximum number of bytes to read in. Default = 2MB
$flags integer See php.net/socket_recv
Résultat string
    public function _read_buffer($length = XPSPL_SOCKET_READ_LENGTH, $flags = MSG_DONTWAIT)
    {
        $r = null;
        $read = @socket_recv($this->get_resource(), $r, $length, $flags);
        if ($read === 0) {
            return false;
        }
        if ($read === false) {
            $error = socket_last_error($this->get_resource());
            $this->error = $error;
            $this->error_str = socket_strerror($this->error);
            // Non-blocking IO
            if ($error == SOCKET_EWOULDBLOCK || ($error = SOCKET_EAGAIN)) {
                ++$this->_read_attempted;
                return true;
            }
            return false;
        }
        $this->_read_attempted = 0;
        if ($r !== null) {
            if (null === $this->_read_buffer) {
                $this->_read_buffer = trim($r);
            } else {
                $this->_read_buffer .= trim($r);
            }
        }
        return true;
    }