Buffer
extends EventEmitter
in package
implements
WritableStreamInterface
Tags
Interfaces, Classes, Traits and Enums
- WritableStreamInterface
Table of Contents
- $buffer : string
- Internal buffer.
- $closed : bool
- Whether the buffer has been closed.
- $loop : LoopInterface
- ReactPHP event loop.
- $reads : array<string|int, Deferred>|array<string|int, int>
- Array of deferred reads waiting to be resolved.
- __construct() : mixed
- close() : void
- {@inheritDoc}
- end() : void
- {@inheritDoc}
- isWritable() : mixed
- {@inheritDoc}
- read() : ExtendedPromiseInterface<mixed, RuntimeException>
- Reads from the buffer and returns a promise.
- readInt16() : ExtendedPromiseInterface<int, RuntimeException>
- Reads a signed 16-bit integer from the buffer.
- readInt32() : ExtendedPromiseInterface<int, RuntimeException>
- Reads a signed 32-bit integer from the buffer.
- write() : bool
- {@inheritDoc}
- readRaw() : string|bool
- Reads from the buffer and returns in a string.
Properties
$buffer
Internal buffer.
private
string
$buffer
= ''
$closed
Whether the buffer has been closed.
private
bool
$closed
= false
$loop
ReactPHP event loop.
private
LoopInterface
$loop
Required for timeouts.
$reads
Array of deferred reads waiting to be resolved.
private
array<string|int, Deferred>|array<string|int, int>
$reads
= []
Methods
__construct()
public
__construct([LoopInterface $loop = null ]) : mixed
Parameters
- $loop : LoopInterface = null
Return values
mixed —close()
{@inheritDoc}
public
close() : void
Return values
void —end()
{@inheritDoc}
public
end([mixed $data = null ]) : void
Parameters
- $data : mixed = null
Return values
void —isWritable()
{@inheritDoc}
public
isWritable() : mixed
Return values
mixed —read()
Reads from the buffer and returns a promise.
public
read(int $length[, null|string $format = null ][, int $timeout = -1 ]) : ExtendedPromiseInterface<mixed, RuntimeException>
The promise will resolve when there are enough bytes in the buffer to read.
Parameters
- $length : int
-
Number of bytes to read.
- $format : null|string = null
-
Format to read the bytes in. See
pack()
. - $timeout : int = -1
-
Time in milliseconds before the read times out.
Tags
Return values
ExtendedPromiseInterface<mixed, RuntimeException> —readInt16()
Reads a signed 16-bit integer from the buffer.
public
readInt16([int $timeout = -1 ]) : ExtendedPromiseInterface<int, RuntimeException>
Parameters
- $timeout : int = -1
-
Time in milliseconds before the read times out.
Tags
Return values
ExtendedPromiseInterface<int, RuntimeException> —readInt32()
Reads a signed 32-bit integer from the buffer.
public
readInt32([int $timeout = -1 ]) : ExtendedPromiseInterface<int, RuntimeException>
Parameters
- $timeout : int = -1
-
Time in milliseconds before the read times out.
Tags
Return values
ExtendedPromiseInterface<int, RuntimeException> —write()
{@inheritDoc}
public
write(mixed $data) : bool
Parameters
- $data : mixed
Return values
bool —readRaw()
Reads from the buffer and returns in a string.
private
readRaw(int $length) : string|bool
Returns false if there were not enough bytes in the buffer.
Parameters
- $length : int
-
Number of bytes to read.
Return values
string|bool —The bytes read, or false if not enough bytes are present.