class EventBuffer (View source)

EventBuffer.

EventBuffer represents Libevent's "evbuffer", an utility functionality for buffered I/O. Event buffers are meant to be generally useful for doing the "buffer" part of buffered network I/O.

Constants

EOL_ANY

EOL_CRLF

EOL_CRLF_STRICT

EOL_LF

EOL_NUL

PTR_SET

PTR_ADD

Properties

int $length
int $contiguous_space

Methods

__construct()

__construct.

bool
add(string $data)

add.

bool
addBuffer(EventBuffer $buf)

addBuffer.

int
appendFrom(EventBuffer $buf, int $len)

appendFrom.

int
copyout(string $data, int $max_bytes)

copyout.

bool
drain(int $len)

drain.

void
enableLocking()

enableLocking.

bool
expand(int $len)

expand.

bool
freeze(bool $at_front)

freeze.

void
lock()

lock.

bool
prepend(string $data)

prepend.

bool
prependBuffer(EventBuffer $buf)

prependBuffer.

string|null
pullup(int $size)

pullup.

string|null
read(int $max_bytes)

read.

int
readFrom(mixed $fd, int $howmuch)

readFrom.

string|null
readLine(int $eol_style)

readLine.

int|false
search(string $what, int $start = 1, int $end = 1)

search.

int|false
searchEol(int $start = 1, int $eol_style = EventBuffer::EOL_ANY)

searchEol.

string
substr(int $start, int $length)

substr.

bool
unfreeze(bool $at_front)

unfreeze.

void
unlock()

unlock.

int|false
write(mixed $fd, int $howmuch)

write.

Details

__construct()

__construct.

Constructs EventBuffer object.

bool add(string $data)

add.

Append data to the end of an event buffer.

Parameters

string $data

String to be appended to the end of the buffer.

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbuffer.add.php

bool addBuffer(EventBuffer $buf)

addBuffer.

Move all data from a buffer provided to the current instance of EventBuffer.

Parameters

EventBuffer $buf

The source EventBuffer object.

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbuffer.addbuffer.php

int appendFrom(EventBuffer $buf, int $len)

appendFrom.

Moves the specified number of bytes from a source buffer to the end of the current buffer.

Parameters

EventBuffer $buf

Source buffer.

int $len

Return Value

int

Returns the number of bytes read.

See also

https://php.net/manual/en/eventbuffer.appendfrom.php

int copyout(string $data, int $max_bytes)

copyout.

Copies out specified number of bytes from the front of the buffer.

Parameters

string $data

Output string.

int $max_bytes

The number of bytes to copy.

Return Value

int

Returns the number of bytes copied, or -1 on failure.

See also

https://php.net/manual/en/eventbuffer.copyout.php

bool drain(int $len)

drain.

Removes specified number of bytes from the front of the buffer without copying it anywhere.

Parameters

int $len

The number of bytes to remove from the buffer.

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbuffer.drain.php

void enableLocking()

enableLocking.

bool expand(int $len)

expand.

Reserves space in buffer.

Parameters

int $len

The number of bytes to reserve for the buffer

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbuffer.expand.php

bool freeze(bool $at_front)

freeze.

Prevent calls that modify an event buffer from succeeding.

Parameters

bool $at_front

Whether to disable changes to the front or end of the buffer.

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbuffer.freeze.php

void lock()

lock.

Acquires a lock on buffer.

bool prepend(string $data)

prepend.

Prepend data to the front of the buffer.

Parameters

string $data

String to be prepended to the front of the buffer.

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbuffer.prepend.php

bool prependBuffer(EventBuffer $buf)

prependBuffer.

Moves all data from source buffer to the front of current buffer.

Parameters

EventBuffer $buf

Source buffer.

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbuffer.prependbuffer.php

string|null pullup(int $size)

pullup.

Linearizes data within buffer and returns it's contents as a string.

Parameters

int $size

The number of bytes required to be contiguous within the buffer.

Return Value

string|null

If size is greater than the number of bytes in the buffer, the function returns null. Otherwise, EventBuffer::pullup returns string.

See also

https://php.net/manual/en/eventbuffer.pullup.php

string|null read(int $max_bytes)

read.

Read data from an evbuffer and drain the bytes read.

Parameters

int $max_bytes

Maximum number of bytes to read from the buffer.

Return Value

string|null

int readFrom(mixed $fd, int $howmuch)

readFrom.

Read data from a file onto the end of the buffer.

Parameters

mixed $fd
int $howmuch

Return Value

int

See also

https://php.net/manual/en/eventbuffer.readfrom.php

string|null readLine(int $eol_style)

readLine.

Extracts a line from the front of the buffer.

Parameters

int $eol_style

One of EventBuffer:EOL_* constants.

Return Value

string|null

See also

https://php.net/manual/en/eventbuffer.readline.php

search.

Scans the buffer for an occurrence of a string.

Parameters

string $what

String to search.

int $start

= 1

int $end

= 1

Return Value

int|false

Returns numeric position of the first occurrence of the string in the buffer, or false if string is not found. This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

See also

https://php.net/manual/en/eventbuffer.search.php

int|false searchEol(int $start = 1, int $eol_style = EventBuffer::EOL_ANY)

searchEol.

Scans the buffer for an occurrence of an end of line.

Parameters

int $start

= 1

int $eol_style

= EOL_ANY

Return Value

int|false

Returns numeric position of the first occurrence of end-of-line symbol in the buffer, or false if not found. This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

See also

https://php.net/manual/en/eventbuffer.searcheol.php

string substr(int $start, int $length)

substr.

Substracts a portion of the buffer data.

Parameters

int $start

The start position of data to be subtracted.

int $length (optional)

Return Value

string

Returns the data subtracted as a string on success, or false on failure.

See also

https://php.net/manual/en/eventbuffer.substr.php

bool unfreeze(bool $at_front)

unfreeze.

Re-enable calls that modify an event buffer.

Parameters

bool $at_front

Whether to enable events at the front or at the end of the buffer.

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbuffer.unfreeze.php

void unlock()

unlock.

Releases lock acquired by EventBuffer::lock.

Return Value

void

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbuffer.unlock.php

int|false write(mixed $fd, int $howmuch)

write.

Write contents of the buffer to a file or socket.

Parameters

mixed $fd

Socket resource, stream or numeric file descriptor normally associated with a socket.

int $howmuch (optional)

Return Value

int|false

Returns the number of bytes written, or false on error.

See also

https://php.net/manual/en/eventbuffer.write.php