The EventBufferEvent class
(PECL event >= 1.2.6-beta)
Introduction
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.
Class synopsis
$dns_base
,
string
$hostname
,
int
$port
[,
int
$family
= EventUtil::AF_UNSPEC
] ) : bool$base
[,
mixed
$socket
= NULL
[,
int
$options
= 0
[,
callable
$readcb
= NULL
[,
callable
$writecb
= NULL
[,
callable
$eventcb
= NULL
]]]]] )$readcb
,
callable
$writecb
,
callable
$eventcb
[,
string
$arg
] ) : void$base
,
EventBufferEvent
$underlying
,
EventSslContext
$ctx
,
int
$state
[,
int
$options
= 0
] ) : EventBufferEvent$base
,
mixed
$socket
,
EventSslContext
$ctx
,
int
$state
[,
int
$options
] ) : EventBufferEventProperties
- fd
-
Numeric file descriptor associated with the buffer event. Normally represents a bound socket. Equals to
NULL
, if there is no file descriptor(socket) associated with the buffer event. - priority
-
The priority of the events used to implement the buffer event.
- input
-
Underlying input buffer object( EventBuffer )
- output
-
Underlying output buffer object( EventBuffer )
Predefined Constants
-
EventBufferEvent::READING
-
An event occurred during a read operation on the bufferevent. See the other flags for which event it was.
-
EventBufferEvent::WRITING
-
An event occurred during a write operation on the bufferevent. See the other flags for which event it was.
-
EventBufferEvent::EOF
-
Got an end-of-file indication on the buffer event.
-
EventBufferEvent::ERROR
-
An error occurred during a bufferevent operation. For more information on what the error was, call EventUtil::getLastSocketErrno() and/or EventUtil::getLastSocketError() .
-
EventBufferEvent::TIMEOUT
-
EventBufferEvent::CONNECTED
-
Finished a requested connection on the bufferevent.
-
EventBufferEvent::OPT_CLOSE_ON_FREE
-
When the buffer event is freed, close the underlying transport. This will close an underlying socket, free an underlying buffer event, etc.
-
EventBufferEvent::OPT_THREADSAFE
-
Automatically allocate locks for the bufferevent, so that it’s safe to use from multiple threads.
-
EventBufferEvent::OPT_DEFER_CALLBACKS
-
When this flag is set, the bufferevent defers all of its callbacks. See » Fast portable non-blocking network programming with Libevent, Deferred callbacks .
-
EventBufferEvent::OPT_UNLOCK_CALLBACKS
-
By default, when the bufferevent is set up to be threadsafe, the buffer event’s locks are held whenever the any user-provided callback is invoked. Setting this option makes Libevent release the buffer event’s lock when it’s invoking the callbacks.
-
EventBufferEvent::SSL_OPEN
-
The SSL handshake is done
-
EventBufferEvent::SSL_CONNECTING
-
SSL is currently performing negotiation as a client
-
EventBufferEvent::SSL_ACCEPTING
-
SSL is currently performing negotiation as a server
Table of Contents
- EventBufferEvent::close — Closes file descriptor associated with the current buffer event
- EventBufferEvent::connect — Connect buffer event's file descriptor to given address or UNIX socket
- EventBufferEvent::connectHost — Connects to a hostname with optionally asyncronous DNS resolving
- EventBufferEvent::__construct — Constructs EventBufferEvent object
- EventBufferEvent::createPair — Creates two buffer events connected to each other
- EventBufferEvent::disable — Disable events read, write, or both on a buffer event
- EventBufferEvent::enable — Enable events read, write, or both on a buffer event
- EventBufferEvent::free — Free a buffer event
- EventBufferEvent::getDnsErrorString — Returns string describing the last failed DNS lookup attempt
- EventBufferEvent::getEnabled — Returns bitmask of events currently enabled on the buffer event
- EventBufferEvent::getInput — Returns underlying input buffer associated with current buffer event
- EventBufferEvent::getOutput — Returns underlying output buffer associated with current buffer event
- EventBufferEvent::read — Read buffer's data
- EventBufferEvent::readBuffer — Drains the entire contents of the input buffer and places them into buf
- EventBufferEvent::setCallbacks — Assigns read, write and event(status) callbacks
- EventBufferEvent::setPriority — Assign a priority to a bufferevent
- EventBufferEvent::setTimeouts — Set the read and write timeout for a buffer event
- EventBufferEvent::setWatermark — Adjusts read and/or write watermarks
- EventBufferEvent::sslError — Returns most recent OpenSSL error reported on the buffer event
- EventBufferEvent::sslFilter — Create a new SSL buffer event to send its data over another buffer event
- EventBufferEvent::sslGetCipherInfo — Returns a textual description of the cipher
- EventBufferEvent::sslGetCipherName — Returns the current cipher name of the SSL connection
- EventBufferEvent::sslGetCipherVersion — Returns version of cipher used by current SSL connection
- EventBufferEvent::sslGetProtocol — Returns the name of the protocol used for current SSL connection
- EventBufferEvent::sslRenegotiate — Tells a bufferevent to begin SSL renegotiation
- EventBufferEvent::sslSocket — Creates a new SSL buffer event to send its data over an SSL on a socket
- EventBufferEvent::write — Adds data to a buffer event's output buffer
- EventBufferEvent::writeBuffer — Adds contents of the entire buffer to a buffer event's output buffer
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-class.eventbufferevent.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.