/** * Reads a chunk of data into the internal read buffer. */ private function readFrame() { $buf = $this->transport_->readAll(4); $val = unpack('N', $buf); $sz = $val[1]; $this->rBuf_ = $this->transport_->readAll($sz); }
private function saslRead_($statusByte = false) { // Read SASL Header if ($statusByte) { $frame = unpack('Cstatus/Nlength', $this->transport_->readAll(5)); } else { $frame = unpack('Nlength', $this->transport_->readAll(4)); } // Read SASL Payload $frame['payload'] = $this->transport_->readAll($frame['length']); return $frame; }
/** * The reason that we customize readAll here is that the majority of PHP * streams are already internally buffered by PHP. The socket stream, for * example, buffers internally and blocks if you call read with $len greater * than the amount of data available, unlike recv() in C. * * Therefore, use the readAll method of the wrapped transport inside * the buffered readAll. */ public function readAll($len) { $have = TStringFuncFactory::create()->strlen($this->rBuf_); if ($have == 0) { $data = $this->transport_->readAll($len); } elseif ($have < $len) { $data = $this->rBuf_; $this->rBuf_ = ''; $data .= $this->transport_->readAll($len - $have); } elseif ($have == $len) { $data = $this->rBuf_; $this->rBuf_ = ''; } elseif ($have > $len) { $data = TStringFuncFactory::create()->substr($this->rBuf_, 0, $len); $this->rBuf_ = TStringFuncFactory::create()->substr($this->rBuf_, $len); } return $data; }