final class EventBufferEvent (View source)

EventBufferEvent.

Represents Libevent's buffer event. Usually an application wants to perform some amount of data buffering in addition to just responding to events. When we want to write data, for example, the usual pattern looks like: Decide that we want to write some data to a connection; put that data in a buffer. Wait for the connection to become writable Write as much of the data as we can Remember how much we wrote, and if we still have more data to write, wait for the connection to become writable again. This buffered I/O pattern is common enough that Libevent provides a generic mechanism for it. A "buffer event" consists of an underlying transport (like a socket), a read buffer, and a write buffer. Instead of regular events, which give callbacks when the underlying transport is ready to be read or written, a buffer event invokes its user-supplied callbacks when it has read or written enough data.

Constants

READING

WRITING

EOF

ERROR

TIMEOUT

CONNECTED

OPT_CLOSE_ON_FREE

OPT_THREADSAFE

OPT_DEFER_CALLBACKS

OPT_UNLOCK_CALLBACKS

SSL_OPEN

SSL_CONNECTING

SSL_ACCEPTING

Properties

int $fd
int $priority
EventBuffer $input
EventBuffer $output

Methods

__construct(EventBase $base, mixed $socket = null, int $options = 0, callable|null $readcb = null, callable|null $writecb = null, callable|null $eventcb = null)

__construct.

bool
close()

close.

bool
connect(string $addr)

connect.

bool
connectHost(EventDnsBase|null $dns_base, string $hostname, int $port, int $family = EventUtil::AF_UNSPEC)

connectHost.

createSslFilter(EventBufferEvent $underlying, EventSslContext $ctx, int $state, int $options = 0)

createSslFilter

static array
createPair(EventBase $base, int $options = 0)

createPair.

bool
disable(int $events)

disable.

bool
enable(int $events)

enable.

void
free()

free.

string
getDnsErrorString()

getDnsErrorString.

int
getEnabled()

getEnabled.

getInput()

getInput.

getOutput()

getOutput.

string|null
read(int $size)

read.

bool
readBuffer(EventBuffer $buf)

readBuffer.

void
setCallbacks(callable $readcb, callable $writecb, callable $eventcb, mixed $arg = null)

setCallbacks.

bool
setPriority(int $priority)

setPriority.

bool
setTimeouts(float $timeout_read, float $timeout_write)

setTimeouts.

void
setWatermark(int $events, int $lowmark, int $highmark)

setWatermark.

false|string
sslError()

sslError.

sslFilter(EventBase $base, EventBufferEvent $underlying, EventSslContext $ctx, int $state, int $options = 0)

sslFilter.

string|false
sslGetCipherInfo()

sslGetCipherInfo.

string|false
sslGetCipherName()

sslGetCipherName.

string|false
sslGetCipherVersion()

sslGetCipherVersion.

string
sslGetProtocol()

sslGetProtocol.

void
sslRenegotiate()

sslRenegotiate.

sslSocket(EventBase $base, mixed $socket, EventSslContext $ctx, int $state, int $options = 0)

sslSocket.

bool
write(string $data)

write.

bool
writeBuffer(EventBuffer $buf)

writeBuffer.

Details

__construct(EventBase $base, mixed $socket = null, int $options = 0, callable|null $readcb = null, callable|null $writecb = null, callable|null $eventcb = null)

__construct.

Constructs EventBufferEvent object.

Parameters

EventBase $base

Event base that should be associated with the new buffer event.

mixed $socket

= null

int $options

= 0

callable|null $readcb

= null

callable|null $writecb

= null

callable|null $eventcb

= null

See also

https://php.net/manual/en/eventbufferevent.construct.php

bool close()

close.

Closes file descriptor associated with the current buffer event.

bool connect(string $addr)

connect.

Connect buffer event's file descriptor to given address or UNIX socket.

Parameters

string $addr

Should contain an IP address with optional port number, or a path to UNIX domain socket. Recognized formats are: [IPv6Address]:port [IPv6Address] IPv6Address IPv4Address:port IPv4Address unix:path Note, 'unix:' prefix is currently not case sensitive.

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbufferevent.connect.php

bool connectHost(EventDnsBase|null $dns_base, string $hostname, int $port, int $family = EventUtil::AF_UNSPEC)

connectHost.

Connects to a hostname with optionally asyncronous DNS.

Parameters

EventDnsBase|null $dns_base

Object of EventDnsBase in case if DNS is to be resolved asynchronously. Otherwise null.

string $hostname

Hostname to connect to. Recognized formats are: www.example.com (hostname) 1.2.3.4 (ipv4address) ::1 (ipv6address) [::1] ([ipv6address])

int $port

Port number

int $family

= EventUtil::AF_UNSPEC

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbufferevent.connecthost.php

EventBufferEvent createSslFilter(EventBufferEvent $underlying, EventSslContext $ctx, int $state, int $options = 0)

static array createPair(EventBase $base, int $options = 0)

createPair.

Creates two buffer events connected to each other.

Parameters

EventBase $base

Associated event base

int $options

= 0

Return Value

array

Returns array of two EventBufferEvent objects connected to each other.

See also

https://php.net/manual/en/eventbufferevent.createpair.php

bool disable(int $events)

disable.

Disable events read, write, or both on a buffer event.

Parameters

int $events

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbufferevent.disable.php

bool enable(int $events)

enable.

Enable events read, write, or both on a buffer event.

Parameters

int $events

Event::READ, Event::WRITE, or Event::READ | Event::WRITE on a buffer event.

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbufferevent.enable.php

void free()

free.

Free a buffer event.

string getDnsErrorString()

getDnsErrorString.

Returns string describing the last failed DNS lookup attempt.

Return Value

string

Returns a string describing DNS lookup error, or an empty string for no error.

See also

https://php.net/manual/en/eventbufferevent.getdnserrorstring.php

int getEnabled()

getEnabled.

Returns bitmask of events currently enabled on the buffer event.

Return Value

int

Returns integer representing a bitmask of events currently enabled on the buffer event

See also

https://php.net/manual/en/eventbufferevent.getenabled.php

EventBuffer getInput()

getInput.

Returns underlying input buffer associated with current buffer event.

Return Value

EventBuffer

Returns instance of EventBuffer input buffer associated with current buffer event.

See also

https://php.net/manual/en/eventbufferevent.getinput.php

EventBuffer getOutput()

getOutput.

Returns underlying output buffer associated with current buffer event.

Return Value

EventBuffer

Returns instance of EventBuffer output buffer associated with current buffer event.

See also

https://php.net/manual/en/eventbufferevent.getoutput.php

string|null read(int $size)

read.

Read buffer's data.

Parameters

int $size

Maximum number of bytes to read

Return Value

string|null

Returns string of data read from the input buffer.

See also

https://php.net/manual/en/eventbufferevent.read.php

bool readBuffer(EventBuffer $buf)

readBuffer.

Drains the entire contents of the input buffer and places them into buf.

Parameters

EventBuffer $buf

Target buffer

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbufferevent.readbuffer.php

void setCallbacks(callable $readcb, callable $writecb, callable $eventcb, mixed $arg = null)

setCallbacks.

Assigns read, write and event(status) callbacks.

Parameters

callable $readcb

Read event callback. See About buffer event callbacks.

callable $writecb

Write event callback. See About buffer event callbacks.

callable $eventcb

Status-change event callback. See About buffer event callbacks.

mixed $arg (optional)

Return Value

void

See also

https://php.net/manual/en/eventbufferevent.setcallbacks.php

bool setPriority(int $priority)

setPriority.

Assign a priority to a bufferevent.

Parameters

int $priority

Priority value.

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbufferevent.setpriority.php

bool setTimeouts(float $timeout_read, float $timeout_write)

setTimeouts.

Set the read and write timeout for a buffer event.

Parameters

float $timeout_read

Read timeout

float $timeout_write

Write timeout

Return Value

bool

Returns true on success or false on failure.

See also

https://php.net/manual/en/eventbufferevent.settimeouts.php

void setWatermark(int $events, int $lowmark, int $highmark)

setWatermark.

Adjusts read and/or write watermarks.

Parameters

int $events

Bitmask of Event::READ, Event::WRITE, or both.

int $lowmark

Minimum watermark value.

int $highmark

Maximum watermark value. 0 means "unlimited".

Return Value

void

See also

https://php.net/manual/en/eventbufferevent.setwatermark.php

false|string sslError()

sslError.

Returns most recent OpenSSL error reported on the buffer event.

Return Value

false|string

Returns OpenSSL error string reported on the buffer event, or false, if there is no more error to return.

See also

https://secure.php.net/manual/en/eventbufferevent.sslerror.php

static EventBufferEvent sslFilter(EventBase $base, EventBufferEvent $underlying, EventSslContext $ctx, int $state, int $options = 0)

sslFilter.

Create a new SSL buffer event to send its data over another buffer event.

Parameters

EventBase $base

Associated event base.

EventBufferEvent $underlying

A socket buffer event to use for this SSL.

EventSslContext $ctx

Object of EventSslContext class.

int $state

The current state of SSL connection: EventBufferEvent::SSL_OPEN, EventBufferEvent::SSL_ACCEPTING or EventBufferEvent::SSL_CONNECTING.

int $options

= 0

Return Value

EventBufferEvent

Returns a new SSL EventBufferEvent object.

See also

https://secure.php.net/manual/en/eventbufferevent.sslfilter.php

string|false sslGetCipherInfo()

sslGetCipherInfo.

Returns a textual description of the cipher.

Return Value

string|false

Returns a textual description of the cipher on success, or false on error.

See also

https://secure.php.net/manual/en/eventbufferevent.sslgetcipherinfo.php

string|false sslGetCipherName()

sslGetCipherName.

Returns the current cipher name of the SSL connection.

Return Value

string|false

Returns the current cipher name of the SSL connection, or false on error.

See also

https://secure.php.net/manual/en/eventbufferevent.sslgetciphername.php

string|false sslGetCipherVersion()

sslGetCipherVersion.

Returns version of cipher used by current SSL connection.

Return Value

string|false

Returns the current cipher version of the SSL connection, or false on error.

See also

https://secure.php.net/manual/en/eventbufferevent.sslgetcipherversion.php

string sslGetProtocol()

sslGetProtocol.

Returns the name of the protocol used for current SSL.

Return Value

string

Returns the name of the protocol used for current SSL connection.

See also

https://secure.php.net/manual/en/eventbufferevent.sslgetprotocol.php

void sslRenegotiate()

sslRenegotiate.

Tells a bufferevent to begin SSL renegotiation.

static EventBufferEvent sslSocket(EventBase $base, mixed $socket, EventSslContext $ctx, int $state, int $options = 0)

sslSocket.

Creates a new SSL buffer event to send its data over an SSL on a socket.

Parameters

EventBase $base

Associated event base.

mixed $socket

Socket to use for this SSL. Can be stream or socket resource, numeric file descriptor, or null. If socket is null, it is assumed that the file descriptor for the socket will be assigned later, for instance, by means of EventBufferEvent::connectHost method.

EventSslContext $ctx

Object of EventSslContext class.

int $state

The current state of SSL connection: EventBufferEvent::SSL_OPEN, EventBufferEvent::SSL_ACCEPTING or EventBufferEvent::SSL_CONNECTING.

int $options (optional)

Return Value

EventBufferEvent

Returns EventBufferEvent object.

See also

https://secure.php.net/manual/en/eventbufferevent.sslsocket.php

bool write(string $data)

write.

Adds data to a buffer event's output buffer.

Parameters

string $data

Data to be added to the underlying buffer.

Return Value

bool

Returns true on success or false on failure.

See also

https://secure.php.net/manual/en/eventbufferevent.write.php

bool writeBuffer(EventBuffer $buf)

writeBuffer.

Adds contents of the entire buffer to a buffer event's output buffer.

Parameters

EventBuffer $buf

Source EventBuffer object.

Return Value

bool

Returns true on success or false on failure.

See also

https://secure.php.net/manual/en/eventbufferevent.writebuffer.php