deimos.event2.event

@file event2/event.h

Core functions for waiting for and receiving events, and using event bases.

Public Imports

deimos.event2.util
public import deimos.event2.util;
deimos.event2.event_struct
public import deimos.event2.event_struct;

Structure to hold information and state for a Libevent dispatch loop.

The event_base lies at the center of Libevent; every application will have one. It keeps track of all pending and active events, and notifies your application of the active ones.

This is an opaque structure; you can allocate one using event_base_new() or event_base_new_with_config().

@see event_base_new(), event_base_free(), event_base_loop(), event_base_new_with_config()

deimos.event2.event_struct
public import deimos.event2.event_struct;

@struct event

Structure to represent a single event.

An event can have some underlying condition it represents: a socket becoming readable or writeable (or both), or a signal becoming raised. (An event that represents no underlying condition is still useful: you can use one to implement a timer, or to communicate between threads.)

Generally, you can create events with event_new(), then make them pending with event_add(). As your event_base runs, it will run the callbacks of an events whose conditions are triggered. When you longer want the event, free it with event_free().

In more depth:

An event may be "pending" (one whose condition we are watching), "active" (one whose condition has triggered and whose callback is about to run), neither, or both. Events come into existence via event_assign() or event_new(), and are then neither active nor pending.

To make an event pending, pass it to event_add(). When doing so, you can also set a timeout for the event.

Events become active during an event_base_loop() call when either their condition has triggered, or when their timeout has elapsed. You can also activate an event manually using event_active(). The even_base loop will run the callbacks of active events; after it has done so, it marks them as no longer active.

You can make an event non-pending by passing it to event_del(). This also makes the event non-active.

Events can be "persistent" or "non-persistent". A non-persistent event becomes non-pending as soon as it is triggered: thus, it only runs at most once per call to event_add(). A persistent event remains pending even when it becomes active: you'll need to event_del() it manually in order to make it non-pending. When a persistent event with a timeout becomes active, its timeout is reset: this means you can use persistent events to implement periodic timeouts.

This should be treated as an opaque structure; you should never read or write any of its fields directly. For backward compatibility with old code, it is defined in the event2/event_struct.h header; including this header may make your code incompatible with other versions of Libevent.

@see event_new(), event_free(), event_assign(), event_get_assignment(), event_add(), event_del(), event_active(), event_pending(), event_get_fd(), event_get_base(), event_get_events(), event_get_callback(), event_get_callback_arg(), event_priority_set()

Members

Aliases

event_callback_fn
alias event_callback_fn = ExternC!(void function(evutil_socket_t, short, void*))

A callback function for an event.

event_fatal_cb
alias event_fatal_cb = ExternC!(void function(int err))

A function to be called if Libevent encounters a fatal internal error.

event_log_cb
alias event_log_cb = ExternC!(void function(int severity, const(char)* msg))

A callback function used to intercept Libevent's log messages.

evsignal_add
alias evsignal_add = event_add

@{

evsignal_del
alias evsignal_del = event_del
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evsignal_initialized
alias evsignal_initialized = event_initialized
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evtimer_add
alias evtimer_add = event_add
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evtimer_del
alias evtimer_del = event_del
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evtimer_initialized
alias evtimer_initialized = event_initialized
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Enums

event_base_config_flag
enum event_base_config_flag

A flag passed to event_config_set_flag().

event_method_feature
enum event_method_feature

A flag used to describe which features an event_base (must) provide.

Functions

event_active
void event_active(event* ev, int res, short ncalls)

Make an event active.

event_add
int event_add(event* ev, const(timeval)* timeout)

Add an event to the set of pending events.

event_assign
int event_assign(event* , event_base* , evutil_socket_t , short , event_callback_fn , void* )

Prepare a new, already-allocated event structure to be added.

event_base_dispatch
int event_base_dispatch(event_base* )

Event dispatching loop

event_base_dump_events
void event_base_dump_events(event_base* , FILE* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
event_base_free
void event_base_free(event_base* )

Deallocate all memory associated with an event_base, and free the base.

event_base_get_features
int event_base_get_features(const(event_base)* base)

Return a bitmask of the features implemented by an event base. This will be a bitwise OR of one or more of the values of event_method_feature

event_base_get_method
const(char)* event_base_get_method(const(event_base)* )

Get the kernel event notification mechanism used by Libevent.

event_base_gettimeofday_cached
int event_base_gettimeofday_cached(event_base* base, timeval* tv)

Sets 'tv' to the current time (as returned by gettimeofday()), looking at the cached value in 'base' if possible, and calling gettimeofday() or clock_gettime() as appropriate if there is no cached time.

event_base_got_break
int event_base_got_break(event_base* )

Checks if the event loop was told to abort immediately by event_loopbreak().

event_base_got_exit
int event_base_got_exit(event_base* )

Checks if the event loop was told to exit by event_loopexit().

event_base_init_common_timeout
const(timeval)* event_base_init_common_timeout(event_base* base, const(timeval)* duration)

Prepare an event_base to use a large number of timeouts with the same duration.

event_base_loop
int event_base_loop(event_base* , int )

Wait for events to become active, and run their callbacks.

event_base_loopbreak
int event_base_loopbreak(event_base* )

Abort the active event_base_loop() immediately.

event_base_loopexit
int event_base_loopexit(event_base* , const(timeval)* )

Exit the event loop after the specified time

event_base_new
event_base* event_base_new()

Create and return a new event_base to use with the rest of Libevent.

event_base_new_with_config
event_base* event_base_new_with_config(const(event_config)* )

Initialize the event API.

event_base_once
int event_base_once(event_base* , evutil_socket_t , short , event_callback_fn , void* , const(timeval)* )

Schedule a one-time event

event_base_priority_init
int event_base_priority_init(event_base* , int )

Set the number of different event priorities

event_base_set
int event_base_set(event_base* , event* )

Associate a different event base with an event.

event_config_avoid_method
int event_config_avoid_method(event_config* cfg, const(char)* method)

Enters an event method that should be avoided into the configuration.

event_config_free
void event_config_free(event_config* cfg)

Deallocates all memory associated with an event configuration object

event_config_new
event_config* event_config_new()

Allocates a new event configuration object.

event_config_require_features
int event_config_require_features(event_config* cfg, int feature)

Enters a required event method feature that the application demands.

event_config_set_flag
int event_config_set_flag(event_config* cfg, int flag)

Sets one or more flags to configure what parts of the eventual event_base will be initialized, and how they'll work.

event_config_set_num_cpus_hint
int event_config_set_num_cpus_hint(event_config* cfg, int cpus)

Records a hint for the number of CPUs in the system. This is used for tuning thread pools, etc, for optimal performance. In Libevent 2.0, it is only on Windows, and only when IOCP is in use.

event_debug_unassign
void event_debug_unassign(event* )

When debugging mode is enabled, informs Libevent that an event should no longer be considered as assigned. When debugging mode is not enabled, does nothing.

event_del
int event_del(event* )

Remove an event from the set of monitored events.

event_enable_debug_mode
void event_enable_debug_mode()

Enable some relatively expensive debugging checks in Libevent that would normally be turned off. Generally, these checks cause code that would otherwise crash mysteriously to fail earlier with an assertion failure. Note that this method MUST be called before any events or event_bases have been created.

event_free
void event_free(event* )

Deallocate a event* returned by event_new().

event_get_assignment
void event_get_assignment(const(event)* event, event_base** base_out, evutil_socket_t* fd_out, short* events_out, event_callback_fn* callback_out, void** arg_out)

Extract _all_ of arguments given to cona given event. The event_base is copied into* base_out, the fd is copied into* fd_out, and so on.

event_get_base
event_base* event_get_base(const(event)* ev)

Get the event_base associated with an event.

event_get_callback
event_callback_fn event_get_callback(const(event)* ev)

Return the callback assigned to an event.

event_get_callback_arg
void* event_get_callback_arg(const(event)* ev)

Return the callback argument assigned to an event.

event_get_events
short event_get_events(const(event)* ev)

Return the events (EV_READ, EV_WRITE, etc) assigned to an event.

event_get_fd
evutil_socket_t event_get_fd(const(event)* ev)

Get the socket or signal assigned to an event, or -1 if the event has no socket.

event_get_signal
int event_get_signal(const(event)* ev)

Get the signal number assigned to a signal event

event_get_struct_event_size
size_t event_get_struct_event_size()

Return the size of event that the Libevent library was compiled with.

event_get_supported_methods
const(char)** event_get_supported_methods()

Gets all event notification mechanisms supported by Libevent.

event_get_version
const(char)* event_get_version()

Get the Libevent version.

event_get_version_number
ev_uint32_t event_get_version_number()

Return a numeric representation of Libevent's version.

event_initialized
int event_initialized(const(event)* ev)

Test if an event structure might be initialized.

event_new
event* event_new(event_base* , evutil_socket_t , short , event_callback_fn , void* )

Allocate and asssign a new event structure, ready to be added.

event_pending
int event_pending(const(event)* ev, short events, timeval* tv)

Checks if a specific event is pending or scheduled.

event_priority_set
int event_priority_set(event* , int )

Assign a priority to an event.

event_reinit
int event_reinit(event_base* base)

Reinitialize the event base after a fork

event_set_fatal_callback
void event_set_fatal_callback(event_fatal_cb cb)

Override Libevent's behavior in the event of a fatal internal error.

event_set_log_callback
void event_set_log_callback(event_log_cb cb)

Redirect Libevent's log messages.

event_set_mem_functions
void event_set_mem_functions(ExternC!(void* function(size_t sz)) malloc_fn, ExternC!(void* function(void* ptr, size_t sz)) realloc_fn, ExternC!(void function(void* ptr)) free_fn)

Override the functions that Libevent uses for memory management.

evsignal_assign
int evsignal_assign(event* ev, event_base* b, evutil_socket_t x, event_callback_fn cb, void* arg)
Undocumented in source. Be warned that the author may not have intended to support it.
evsignal_new
int evsignal_new(event_base* b, evutil_socket_t x, event_callback_fn cb, void* arg)
Undocumented in source. Be warned that the author may not have intended to support it.
evsignal_pending
int evsignal_pending(const(event)* ev, timeval* tv)
Undocumented in source. Be warned that the author may not have intended to support it.
evsignal_pending
int evsignal_pending(const(event)* ev, timeval* tv)
Undocumented in source. Be warned that the author may not have intended to support it.
evtimer_assign
int evtimer_assign(event* ev, event_base* b, event_callback_fn cb, void* arg)

@{

Manifest constants

EVENT_MAX_PRIORITIES
enum EVENT_MAX_PRIORITIES;

Largest number of priorities that Libevent can support.

EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
enum EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED;

This definition is present if Libevent was built with support for event_set_mem_functions()

EVLOOP_NONBLOCK
enum EVLOOP_NONBLOCK;

Do not block: see which events are ready now, run the callbacks * of the highest-priority ones, then exit.

EVLOOP_ONCE
enum EVLOOP_ONCE;

Block until we have an active event, then exit once all active events * have had their callbacks run.

EV_ET
enum EV_ET;

Select edge-triggered behavior, if supported by the backend.

EV_PERSIST
enum EV_PERSIST;

Persistent event: won't get removed automatically when activated.

EV_READ
enum EV_READ;

Wait for a socket or FD to become readable

EV_SIGNAL
enum EV_SIGNAL;

Wait for a POSIX signal to be raised

EV_TIMEOUT
enum EV_TIMEOUT;

Indicates that a timeout has occurred. It's not necessary to pass * this flag to event_for new()/event_assign() to get a timeout.

EV_WRITE
enum EV_WRITE;

Wait for a socket or FD to become writeable

LIBEVENT_VERSION
enum LIBEVENT_VERSION;

As event_get_version, but gives the version of Libevent's headers.

LIBEVENT_VERSION_NUMBER
enum LIBEVENT_VERSION_NUMBER;

As event_get_version_number, but gives the version number of Libevent's headers.

_EVENT_LOG_DEBUG
enum _EVENT_LOG_DEBUG;

@{

_EVENT_LOG_ERR
enum _EVENT_LOG_ERR;
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
_EVENT_LOG_MSG
enum _EVENT_LOG_MSG;
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
_EVENT_LOG_WARN
enum _EVENT_LOG_WARN;
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Structs

event_config
struct event_config

Configuration for an event_base.

Meta