# The Event class

(PECL event >= 1.2.6-beta)

## 简介

Event class represents and event firing on a file descriptor being ready to read from or write to; a file descriptor becoming ready to read from or write to(edge-triggered I/O only); a timeout expiring; a signal occurring; a user-triggered event.

Every event is associated with EventBase. However, event will never fire until it is added (via Event::add() ). An added event remains in pending state until the registered event occurs, thus turning it to active state. To handle events user may register a callback which is called when event becomes active. If event is configured persistent, it remains pending. If it is not persistent, it stops being pending when it's callback runs. Event::del() method deletes event, thus making it non-pending. By means of Event::add() method it could be added again.

## 类摘要

final class Event {
/* 常量 */
const int ET = 32;
const int PERSIST = 16;
const int READ = 2;
const int WRITE = 4;
const int SIGNAL = 8;
const int TIMEOUT = 1;
/* 属性 */
public readonly bool $pending;
/* 方法 */
public function add( float `$timeout` = ?): bool
public function __construct(
EventBase `$base` ,
mixed `$fd` ,
int `$what` ,
callable `$cb` ,
mixed `$arg` = NULL
)
public function del(): bool
public function free(): void
public static function getSupportedMethods(): array
public function pending( int `$flags` ): bool
public function set(
EventBase `$base` ,
mixed `$fd` ,
int `$what` = ?,
callable `$cb` = ?,
mixed `$arg` = ?
): bool
public function setPriority( int `$priority` ): bool
public function setTimer( EventBase `$base` , callable `$cb` , mixed `$arg` = ?): bool
public static function signal(
EventBase `$base` ,
int `$signum` ,
callable `$cb` ,
mixed `$arg` = ?
): Event
public static function timer( EventBase `$base` , callable `$cb` , mixed `$arg` = ?): Event
}

## 属性

pending

  Whether event is pending. See About event persistence.

## 预定义常量

`Event::ET`

  Indicates that the event should be edge-triggered, if the underlying event base backend supports edge-triggered events. This affects the semantics of `Event::READ` and `Event::WRITE`.

`Event::PERSIST`

  Indicates that the event is persistent. See About event persistence.

`Event::READ`

  This flag indicates an event that becomes active when the provided file descriptor(usually a stream resource, or socket) is ready for reading.

`Event::WRITE`
  This flag indicates an event that becomes active when the provided file descriptor(usually a stream resource, or socket) is ready for writing.
`Event::SIGNAL`

  Used to implement signal detection. See "Constructing signal events" below.

`Event::TIMEOUT`

  This flag indicates an event that becomes active after a timeout elapses.

  The `Event::TIMEOUT` flag is ignored when constructing an event: one can either set a timeout when event is added, or not. It is set in the `$what` argument to the callback function when a timeout has occurred.

## 目录

- Event::add — Makes event pending
- Event::addSignal — 别名 Event::add
- Event::addTimer — 别名 Event::add
- Event::__construct — Constructs Event object
- Event::del — Makes event non-pending
- Event::delSignal — 别名 Event::del
- Event::delTimer — 别名 Event::del
- Event::free — Make event non-pending and free resources allocated for this event
- Event::getSupportedMethods — Returns array of the names of the methods supported in this version of Libevent
- Event::pending — Detects whether event is pending or scheduled
- Event::set — Re-configures event
- Event::setPriority — Set event priority
- Event::setTimer — Re-configures timer event
- Event::signal — Constructs signal event object
- Event::timer — Constructs timer event object

`↑` and `↓` to navigate • `Enter` to select • `Esc` to close • `/` to open