/** * @coroutine * * Flushes the contents of the internal buffer to the underlying stream. * * @return \Generator * * @resolve int Number of bytes written to the stream. * * @throws \Icicle\Awaitable\Exception\TimeoutException If the operation times out. * @throws \Icicle\Stream\Exception\UnwritableException If the stream is no longer writable. * @throws \Icicle\Stream\Exception\ClosedException If the stream is unexpectedly closed. */ public function flush() : \Generator { if ($this->buffer->isEmpty()) { return 0; } return yield from $this->stream->write($this->buffer->drain(), $this->timeout); }
/** * Returns bytes from the buffer based on the current length or current search byte. * * @return string */ private function remove() : string { if (null !== $this->byte && false !== ($position = $this->buffer->search($this->byte))) { if (0 === $this->length || $position < $this->length) { return $this->buffer->shift($position + 1); } return $this->buffer->shift($this->length); } if (0 === $this->length) { return $this->buffer->drain(); } return $this->buffer->shift($this->length); }