public function testApiSearch_FindsProperIndex_WhenReverseIsPassed() { $search = substr($this->initialString, 0, 3); $this->buffer->push($this->initialString); $index = $this->buffer->search($search, true); $this->assertSame(strlen($this->initialString), $index); }
/** * @override */ public function write($text) { if (!$this->writable) { return $this->throwAndEmitException(new IoWriteException('Stream is no longer writable.')); } $this->buffer->push($text); if (!$this->listening && !$this->paused) { $this->listening = true; $this->loop->addWriteStream($this->resource, [$this, 'handleWrite']); } return $this->buffer->length() < $this->bufferSize; }
/** * @override */ public function readResponse(BufferInterface $buffer, $data) { $buffer->push($data); if (($position = $buffer->search(self::HTTP_EOM)) === false) { if ($buffer->length() > $this->maxStartLineLength) { throw new IoReadException(sprintf('Message start line exceeded maximum size of %d bytes.', $this->maxStartLineLength)); } return null; } try { $response = $this->parser->parseResponse($buffer->drain()); } catch (Error $ex) { throw new InvalidFormatException('Could not parse start line.'); } catch (Exception $ex) { throw new InvalidFormatException('Could not parse start line.'); } return $response; }