.TH "event2/event.h" 3 "Tue Jan 31 2017" "libevent" \" -*- nroff -*- .ad l .nh .SH NAME event2/event.h \- Core functions for waiting for and receiving events, and using event bases\&. .SH SYNOPSIS .br .PP \fC#include \fP .br \fC#include \fP .br \fC#include \fP .br \fC#include \fP .br .SS "Data Structures" .in +1c .ti -1c .RI "struct \fBevent\fP" .br .RI "\fIStructure to represent a single event\&. \fP" .ti -1c .RI "struct \fBevent_base\fP" .br .RI "\fIStructure to hold information and state for a Libevent dispatch loop\&. \fP" .ti -1c .RI "struct \fBevent_config\fP" .br .RI "\fIConfiguration for an \fBevent_base\fP\&. \fP" .in -1c .SS "Macros" .in +1c .ti -1c .RI "#define \fB_EVENT_LOG_DEBUG\fP EVENT_LOG_DEBUG" .br .ti -1c .RI "#define \fB_EVENT_LOG_ERR\fP EVENT_LOG_ERR" .br .ti -1c .RI "#define \fB_EVENT_LOG_MSG\fP EVENT_LOG_MSG" .br .ti -1c .RI "#define \fB_EVENT_LOG_WARN\fP EVENT_LOG_WARN" .br .ti -1c .RI "#define \fBEVENT_DBG_ALL\fP 0xffffffffu" .br .ti -1c .RI "#define \fBEVENT_DBG_NONE\fP 0" .br .ti -1c .RI "#define \fBevent_get_signal\fP(ev) ((int)\fBevent_get_fd\fP(ev))" .br .RI "\fIGet the signal number assigned to a signal event\&. \fP" .ti -1c .RI "#define \fBEVENT_MAX_PRIORITIES\fP 256" .br .RI "\fILargest number of priorities that Libevent can support\&. \fP" .ti -1c .RI "#define \fBEVENT_SET_MEM_FUNCTIONS_IMPLEMENTED\fP" .br .RI "\fIThis definition is present if Libevent was built with support for \fBevent_set_mem_functions()\fP \fP" .ti -1c .RI "#define \fBLIBEVENT_VERSION\fP EVENT__VERSION" .br .RI "\fIAs event_get_version, but gives the version of Libevent's headers\&. \fP" .ti -1c .RI "#define \fBLIBEVENT_VERSION_NUMBER\fP EVENT__NUMERIC_VERSION" .br .RI "\fIAs event_get_version_number, but gives the version number of Libevent's headers\&. \fP" .in -1c .PP .RI "\fBevent type flag\fP" .br Flags to pass to \fBevent_base_get_num_events()\fP to specify the kinds of events we want to aggregate counts for .PP .in +1c .in +1c .ti -1c .RI "#define \fBEVENT_BASE_COUNT_ACTIVE\fP 1U" .br .RI "\fIcount the number of active events, which have been triggered\&. \fP" .ti -1c .RI "#define \fBEVENT_BASE_COUNT_VIRTUAL\fP 2U" .br .RI "\fIcount the number of virtual events, which is used to represent an internal condition, other than a pending event, that keeps the loop from exiting\&. \fP" .ti -1c .RI "#define \fBEVENT_BASE_COUNT_ADDED\fP 4U" .br .RI "\fIcount the number of events which have been added to event base, including internal events\&. \fP" .in -1c .in -1c .PP .RI "\fBLog severities\fP" .br .in +1c .in +1c .ti -1c .RI "#define \fBEVENT_LOG_DEBUG\fP 0" .br .ti -1c .RI "#define \fBEVENT_LOG_MSG\fP 1" .br .ti -1c .RI "#define \fBEVENT_LOG_WARN\fP 2" .br .ti -1c .RI "#define \fBEVENT_LOG_ERR\fP 3" .br .in -1c .in -1c .PP .RI "\fBLoop flags\fP" .br These flags control the behavior of \fBevent_base_loop()\fP\&. .PP .in +1c .in +1c .ti -1c .RI "#define \fBEVLOOP_ONCE\fP 0x01" .br .RI "\fIBlock until we have an active event, then exit once all active events have had their callbacks run\&. \fP" .ti -1c .RI "#define \fBEVLOOP_NONBLOCK\fP 0x02" .br .RI "\fIDo not block: see which events are ready now, run the callbacks of the highest-priority ones, then exit\&. \fP" .ti -1c .RI "#define \fBEVLOOP_NO_EXIT_ON_EMPTY\fP 0x04" .br .RI "\fIDo not exit the loop because we have no pending events\&. \fP" .in -1c .in -1c .PP .RI "\fBevent flags\fP" .br Flags to pass to \fBevent_new()\fP, \fBevent_assign()\fP, \fBevent_pending()\fP, and anything else with an argument of the form 'short events' .PP .in +1c .in +1c .ti -1c .RI "#define \fBEV_TIMEOUT\fP 0x01" .br .RI "\fIIndicates that a timeout has occurred\&. \fP" .ti -1c .RI "#define \fBEV_READ\fP 0x02" .br .RI "\fIWait for a socket or FD to become readable\&. \fP" .ti -1c .RI "#define \fBEV_WRITE\fP 0x04" .br .RI "\fIWait for a socket or FD to become writeable\&. \fP" .ti -1c .RI "#define \fBEV_SIGNAL\fP 0x08" .br .RI "\fIWait for a POSIX signal to be raised\&. \fP" .ti -1c .RI "#define \fBEV_PERSIST\fP 0x10" .br .RI "\fIPersistent event: won't get removed automatically when activated\&. \fP" .ti -1c .RI "#define \fBEV_ET\fP 0x20" .br .RI "\fISelect edge-triggered behavior, if supported by the backend\&. \fP" .ti -1c .RI "#define \fBEV_FINALIZE\fP 0x40" .br .RI "\fIIf this option is provided, then \fBevent_del()\fP will not block in one thread while waiting for the event callback to complete in another thread\&. \fP" .ti -1c .RI "#define \fBEV_CLOSED\fP 0x80" .br .RI "\fIDetects connection close events\&. \fP" .in -1c .in -1c .PP .RI "\fBevtimer_* macros\fP" .br Aliases for working with one-shot timer events .PP .in +1c .in +1c .ti -1c .RI "#define \fBevtimer_assign\fP(ev, b, cb, arg) \fBevent_assign\fP((ev), (b), \-1, 0, (cb), (arg))" .br .ti -1c .RI "#define \fBevtimer_new\fP(b, cb, arg) \fBevent_new\fP((b), \-1, 0, (cb), (arg))" .br .ti -1c .RI "#define \fBevtimer_add\fP(ev, tv) \fBevent_add\fP((ev), (tv))" .br .ti -1c .RI "#define \fBevtimer_del\fP(ev) \fBevent_del\fP(ev)" .br .ti -1c .RI "#define \fBevtimer_pending\fP(ev, tv) \fBevent_pending\fP((ev), \fBEV_TIMEOUT\fP, (tv))" .br .ti -1c .RI "#define \fBevtimer_initialized\fP(ev) \fBevent_initialized\fP(ev)" .br .in -1c .in -1c .PP .RI "\fBevsignal_* macros\fP" .br Aliases for working with signal events .PP .in +1c .in +1c .ti -1c .RI "#define \fBevsignal_add\fP(ev, tv) \fBevent_add\fP((ev), (tv))" .br .ti -1c .RI "#define \fBevsignal_assign\fP(ev, b, x, cb, arg) \fBevent_assign\fP((ev), (b), (x), \fBEV_SIGNAL\fP|\fBEV_PERSIST\fP, cb, (arg))" .br .ti -1c .RI "#define \fBevsignal_new\fP(b, x, cb, arg) \fBevent_new\fP((b), (x), \fBEV_SIGNAL\fP|\fBEV_PERSIST\fP, (cb), (arg))" .br .ti -1c .RI "#define \fBevsignal_del\fP(ev) \fBevent_del\fP(ev)" .br .ti -1c .RI "#define \fBevsignal_pending\fP(ev, tv) \fBevent_pending\fP((ev), \fBEV_SIGNAL\fP, (tv))" .br .ti -1c .RI "#define \fBevsignal_initialized\fP(ev) \fBevent_initialized\fP(ev)" .br .in -1c .in -1c .SS "Typedefs" .in +1c .ti -1c .RI "typedef int(* \fBevent_base_foreach_event_cb\fP) (const struct \fBevent_base\fP *, const struct \fBevent\fP *, void *)" .br .RI "\fICallback for iterating events in an event base via event_base_foreach_event\&. \fP" .ti -1c .RI "typedef void(* \fBevent_callback_fn\fP) (\fBevutil_socket_t\fP, short, void *)" .br .RI "\fIA callback function for an event\&. \fP" .ti -1c .RI "typedef void(* \fBevent_fatal_cb\fP) (int err)" .br .RI "\fIA function to be called if Libevent encounters a fatal internal error\&. \fP" .ti -1c .RI "typedef void(* \fBevent_finalize_callback_fn\fP) (struct \fBevent\fP *, void *)" .br .RI "\fICallback type for event_finalize and event_free_finalize()\&. \fP" .ti -1c .RI "typedef void(* \fBevent_log_cb\fP) (int severity, const char *msg)" .br .RI "\fIA callback function used to intercept Libevent's log messages\&. \fP" .in -1c .SS "Enumerations" .in +1c .ti -1c .RI "enum \fBevent_base_config_flag\fP { \fBEVENT_BASE_FLAG_NOLOCK\fP = 0x01, \fBEVENT_BASE_FLAG_IGNORE_ENV\fP = 0x02, \fBEVENT_BASE_FLAG_STARTUP_IOCP\fP = 0x04, \fBEVENT_BASE_FLAG_NO_CACHE_TIME\fP = 0x08, \fBEVENT_BASE_FLAG_EPOLL_USE_CHANGELIST\fP = 0x10, \fBEVENT_BASE_FLAG_PRECISE_TIMER\fP = 0x20 } .RI "\fIA flag passed to \fBevent_config_set_flag()\fP\&. \fP"" .br .ti -1c .RI "enum \fBevent_method_feature\fP { \fBEV_FEATURE_ET\fP = 0x01, \fBEV_FEATURE_O1\fP = 0x02, \fBEV_FEATURE_FDS\fP = 0x04, \fBEV_FEATURE_EARLY_CLOSE\fP = 0x08 } .RI "\fIA flag used to describe which features an \fBevent_base\fP (must) provide\&. \fP"" .br .in -1c .SS "Functions" .in +1c .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_active\fP (struct \fBevent\fP *ev, int res, short ncalls)" .br .RI "\fIMake an event active\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_add\fP (struct \fBevent\fP *ev, const struct timeval *timeout)" .br .RI "\fIAdd an event to the set of pending events\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_assign\fP (struct \fBevent\fP *, struct \fBevent_base\fP *, \fBevutil_socket_t\fP, short, \fBevent_callback_fn\fP, void *)" .br .RI "\fIPrepare a new, already-allocated event structure to be added\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_base_active_by_fd\fP (struct \fBevent_base\fP *base, \fBevutil_socket_t\fP fd, short events)" .br .RI "\fIActivates all pending events for the given fd and event mask\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_base_active_by_signal\fP (struct \fBevent_base\fP *base, int sig)" .br .RI "\fIActivates all pending signals with a given signal number\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_dispatch\fP (struct \fBevent_base\fP *)" .br .RI "\fIEvent dispatching loop\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_base_dump_events\fP (struct \fBevent_base\fP *, FILE *)" .br .RI "\fIWrites a human-readable description of all inserted and/or active events to a provided stdio stream\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_foreach_event\fP (struct \fBevent_base\fP *base, \fBevent_base_foreach_event_cb\fP fn, void *arg)" .br .RI "\fIIterate over all added or active events events in an event loop, and invoke a given callback on each one\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_base_free\fP (struct \fBevent_base\fP *)" .br .RI "\fIDeallocate all memory associated with an \fBevent_base\fP, and free the base\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_base_free_nofinalize\fP (struct \fBevent_base\fP *)" .br .RI "\fIAs event_free, but do not run finalizers\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_get_features\fP (const struct \fBevent_base\fP *base)" .br .RI "\fIReturn a bitmask of the features implemented by an event base\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_get_max_events\fP (struct \fBevent_base\fP *, unsigned int, int)" .br .RI "\fIGet the maximum number of events in a given \fBevent_base\fP as specified in the flags\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL const char * \fBevent_base_get_method\fP (const struct \fBevent_base\fP *)" .br .RI "\fIGet the kernel event notification mechanism used by Libevent\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_get_npriorities\fP (struct \fBevent_base\fP *eb)" .br .RI "\fIGet the number of different event priorities\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_get_num_events\fP (struct \fBevent_base\fP *, unsigned int)" .br .RI "\fIGets the number of events in \fBevent_base\fP, as specified in the flags\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL struct \fBevent\fP * \fBevent_base_get_running_event\fP (struct \fBevent_base\fP *base)" .br .RI "\fIIf called from within the callback for an event, returns that event\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_gettimeofday_cached\fP (struct \fBevent_base\fP *base, struct timeval *tv)" .br .RI "\fISets '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\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_got_break\fP (struct \fBevent_base\fP *)" .br .RI "\fIChecks if the event loop was told to abort immediately by \fBevent_base_loopbreak()\fP\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_got_exit\fP (struct \fBevent_base\fP *)" .br .RI "\fIChecks if the event loop was told to exit by \fBevent_base_loopexit()\fP\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL const struct timeval * \fBevent_base_init_common_timeout\fP (struct \fBevent_base\fP *base, const struct timeval *duration)" .br .RI "\fIPrepare an \fBevent_base\fP to use a large number of timeouts with the same duration\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_loop\fP (struct \fBevent_base\fP *, int)" .br .RI "\fIWait for events to become active, and run their callbacks\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_loopbreak\fP (struct \fBevent_base\fP *)" .br .RI "\fIAbort the active \fBevent_base_loop()\fP immediately\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_loopcontinue\fP (struct \fBevent_base\fP *)" .br .RI "\fITell the active \fBevent_base_loop()\fP to scan for new events immediately\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_loopexit\fP (struct \fBevent_base\fP *, const struct timeval *)" .br .RI "\fIExit the event loop after the specified time\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL struct \fBevent_base\fP * \fBevent_base_new\fP (void)" .br .RI "\fICreate and return a new \fBevent_base\fP to use with the rest of Libevent\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL struct \fBevent_base\fP * \fBevent_base_new_with_config\fP (const struct \fBevent_config\fP *)" .br .RI "\fIInitialize the event API\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_once\fP (struct \fBevent_base\fP *, \fBevutil_socket_t\fP, short, \fBevent_callback_fn\fP, void *, const struct timeval *)" .br .RI "\fISchedule a one-time event\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_priority_init\fP (struct \fBevent_base\fP *, int)" .br .RI "\fISet the number of different event priorities\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_set\fP (struct \fBevent_base\fP *, struct \fBevent\fP *)" .br .RI "\fIAssociate a different event base with an event\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_base_update_cache_time\fP (struct \fBevent_base\fP *base)" .br .RI "\fIUpdate cached_tv in the 'base' to the current time\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_config_avoid_method\fP (struct \fBevent_config\fP *cfg, const char *method)" .br .RI "\fIEnters an event method that should be avoided into the configuration\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_config_free\fP (struct \fBevent_config\fP *cfg)" .br .RI "\fIDeallocates all memory associated with an event configuration object\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL struct \fBevent_config\fP * \fBevent_config_new\fP (void)" .br .RI "\fIAllocates a new event configuration object\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_config_require_features\fP (struct \fBevent_config\fP *cfg, int feature)" .br .RI "\fIEnters a required event method feature that the application demands\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_config_set_flag\fP (struct \fBevent_config\fP *cfg, int flag)" .br .RI "\fISets one or more flags to configure what parts of the eventual \fBevent_base\fP will be initialized, and how they'll work\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_config_set_max_dispatch_interval\fP (struct \fBevent_config\fP *cfg, const struct timeval *max_interval, int max_callbacks, int min_priority)" .br .RI "\fIRecord an interval and/or a number of callbacks after which the event base should check for new events\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_config_set_num_cpus_hint\fP (struct \fBevent_config\fP *cfg, int cpus)" .br .RI "\fIRecords a hint for the number of CPUs in the system\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_debug_unassign\fP (struct \fBevent\fP *)" .br .RI "\fIWhen debugging mode is enabled, informs Libevent that an event should no longer be considered as assigned\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_del\fP (struct \fBevent\fP *)" .br .RI "\fIRemove an event from the set of monitored events\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_del_block\fP (struct \fBevent\fP *ev)" .br .RI "\fIAs \fBevent_del()\fP, but always blocks while the event's callback is running in another thread, even if the event was constructed with the EV_FINALIZE flag\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_del_noblock\fP (struct \fBevent\fP *ev)" .br .RI "\fIAs \fBevent_del()\fP, but never blocks while the event's callback is running in another thread, even if the event was constructed without the EV_FINALIZE flag\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_enable_debug_logging\fP (ev_uint32_t which)" .br .RI "\fITurn on debugging logs and have them sent to the default log handler\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_enable_debug_mode\fP (void)" .br .RI "\fIEnable some relatively expensive debugging checks in Libevent that would normally be turned off\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_free\fP (struct \fBevent\fP *)" .br .RI "\fIDeallocate a struct event * returned by \fBevent_new()\fP\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_get_assignment\fP (const struct \fBevent\fP *\fBevent\fP, struct \fBevent_base\fP **base_out, \fBevutil_socket_t\fP *fd_out, short *events_out, \fBevent_callback_fn\fP *callback_out, void **arg_out)" .br .RI "\fIExtract \fIall\fP of arguments given to construct a given event\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL struct \fBevent_base\fP * \fBevent_get_base\fP (const struct \fBevent\fP *ev)" .br .RI "\fIGet the \fBevent_base\fP associated with an event\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL \fBevent_callback_fn\fP \fBevent_get_callback\fP (const struct \fBevent\fP *ev)" .br .RI "\fIReturn the callback assigned to an event\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void * \fBevent_get_callback_arg\fP (const struct \fBevent\fP *ev)" .br .RI "\fIReturn the callback argument assigned to an event\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL short \fBevent_get_events\fP (const struct \fBevent\fP *ev)" .br .RI "\fIReturn the events (EV_READ, EV_WRITE, etc) assigned to an event\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL \fBevutil_socket_t\fP \fBevent_get_fd\fP (const struct \fBevent\fP *ev)" .br .RI "\fIGet the socket or signal assigned to an event, or -1 if the event has no socket\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_get_priority\fP (const struct \fBevent\fP *ev)" .br .RI "\fIReturn the priority of an event\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL size_t \fBevent_get_struct_event_size\fP (void)" .br .RI "\fIReturn the size of struct event that the Libevent library was compiled with\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL const char ** \fBevent_get_supported_methods\fP (void)" .br .RI "\fIGets all event notification mechanisms supported by Libevent\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL const char * \fBevent_get_version\fP (void)" .br .RI "\fIGet the Libevent version\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL ev_uint32_t \fBevent_get_version_number\fP (void)" .br .RI "\fIReturn a numeric representation of Libevent's version\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_gettime_monotonic\fP (struct \fBevent_base\fP *base, struct timeval *tp)" .br .RI "\fIQuery the current monotonic time from a the timer for a struct \fBevent_base\fP\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_initialized\fP (const struct \fBevent\fP *ev)" .br .RI "\fITest if an event structure might be initialized\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL struct \fBevent\fP * \fBevent_new\fP (struct \fBevent_base\fP *, \fBevutil_socket_t\fP, short, \fBevent_callback_fn\fP, void *)" .br .RI "\fIAllocate and asssign a new event structure, ready to be added\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_pending\fP (const struct \fBevent\fP *ev, short events, struct timeval *tv)" .br .RI "\fIChecks if a specific event is pending or scheduled\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_priority_set\fP (struct \fBevent\fP *, int)" .br .RI "\fIAssign a priority to an event\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_reinit\fP (struct \fBevent_base\fP *base)" .br .RI "\fIReinitialize the event base after a fork\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_remove_timer\fP (struct \fBevent\fP *ev)" .br .RI "\fIRemove a timer from a pending event without removing the event itself\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void * \fBevent_self_cbarg\fP (void)" .br .RI "\fIReturn a value used to specify that the event itself must be used as the callback argument\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_set_fatal_callback\fP (\fBevent_fatal_cb\fP cb)" .br .RI "\fIOverride Libevent's behavior in the event of a fatal internal error\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_set_log_callback\fP (\fBevent_log_cb\fP cb)" .br .RI "\fIRedirect Libevent's log messages\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBevent_set_mem_functions\fP (void *(*malloc_fn)(size_t sz), void *(*realloc_fn)(void *ptr, size_t sz), void(*free_fn)(void *ptr))" .br .RI "\fIOverride the functions that Libevent uses for memory management\&. \fP" .ti -1c .RI "EVENT2_EXPORT_SYMBOL void \fBlibevent_global_shutdown\fP (void)" .br .RI "\fIRelease up all globally-allocated resources allocated by Libevent\&. \fP" .in -1c .PP .RI "\fBFinalization functions\fP" .br These functions are used to safely tear down an event in a multithreaded application\&. .PP If you construct your events with EV_FINALIZE to avoid deadlocks, you will need a way to remove an event in the certainty that it will definitely not be running its callback when you deallocate it and its callback argument\&. .PP To do this, call one of event_finalize() or event_free_finalize with 0 for its first argument, the event to tear down as its second argument, and a callback function as its third argument\&. The callback will be invoked as part of the event loop, with the event's priority\&. .PP After you call a finalizer function, \fBevent_add()\fP and \fBevent_active()\fP will no longer work on the event, and \fBevent_del()\fP will produce a no-op\&. You must not try to change the event's fields with \fBevent_assign()\fP or \fBevent_set()\fP while the finalize callback is in progress\&. Once the callback has been invoked, you should treat the event structure as containing uninitialized memory\&. .PP The event_free_finalize() function frees the event after it's finalized; event_finalize() does not\&. .PP A finalizer callback must not make events pending or active\&. It must not add events, activate events, or attempt to 'resucitate' the event being finalized in any way\&. .PP THIS IS AN EXPERIMENTAL API\&. IT MIGHT CHANGE BEFORE THE LIBEVENT 2\&.1 SERIES BECOMES STABLE\&. .PP \fBReturns:\fP .RS 4 0 on succes, -1 on failure\&. .RE .PP .PP .in +1c .in +1c .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_finalize\fP (unsigned, struct \fBevent\fP *, \fBevent_finalize_callback_fn\fP)" .br .ti -1c .RI "EVENT2_EXPORT_SYMBOL int \fBevent_free_finalize\fP (unsigned, struct \fBevent\fP *, \fBevent_finalize_callback_fn\fP)" .br .in -1c .in -1c .SH "Detailed Description" .PP Core functions for waiting for and receiving events, and using event bases\&. .SH "Macro Definition Documentation" .PP .SS "#define EV_CLOSED 0x80" .PP Detects connection close events\&. You can use this to detect when a connection has been closed, without having to read all the pending data from a connection\&. .PP Not all backends support EV_CLOSED\&. To detect or require it, use the feature flag EV_FEATURE_EARLY_CLOSE\&. .SS "#define EV_ET 0x20" .PP Select edge-triggered behavior, if supported by the backend\&. .SS "#define EV_FINALIZE 0x40" .PP If this option is provided, then \fBevent_del()\fP will not block in one thread while waiting for the event callback to complete in another thread\&. To use this option safely, you may need to use event_finalize() or event_free_finalize() in order to safely tear down an event in a multithreaded application\&. See those functions for more information\&. .PP THIS IS AN EXPERIMENTAL API\&. IT MIGHT CHANGE BEFORE THE LIBEVENT 2\&.1 SERIES BECOMES STABLE\&. .SS "#define EV_PERSIST 0x10" .PP Persistent event: won't get removed automatically when activated\&. When a persistent event with a timeout becomes activated, its timeout is reset to 0\&. .SS "#define EV_TIMEOUT 0x01" .PP Indicates that a timeout has occurred\&. It's not necessary to pass this flag to event_for new()/event_assign() to get a timeout\&. .SS "#define EVENT_BASE_COUNT_ACTIVE 1U" .PP count the number of active events, which have been triggered\&. .SS "#define EVENT_BASE_COUNT_ADDED 4U" .PP count the number of events which have been added to event base, including internal events\&. .SS "#define EVENT_BASE_COUNT_VIRTUAL 2U" .PP count the number of virtual events, which is used to represent an internal condition, other than a pending event, that keeps the loop from exiting\&. .SS "#define EVENT_MAX_PRIORITIES 256" .PP Largest number of priorities that Libevent can support\&. .SS "#define EVLOOP_NO_EXIT_ON_EMPTY 0x04" .PP Do not exit the loop because we have no pending events\&. Instead, keep running until \fBevent_base_loopexit()\fP or \fBevent_base_loopbreak()\fP makes us stop\&. .SS "#define EVLOOP_NONBLOCK 0x02" .PP Do not block: see which events are ready now, run the callbacks of the highest-priority ones, then exit\&. .SS "#define EVLOOP_ONCE 0x01" .PP Block until we have an active event, then exit once all active events have had their callbacks run\&. .SS "#define LIBEVENT_VERSION EVENT__VERSION" .PP As event_get_version, but gives the version of Libevent's headers\&. .SS "#define LIBEVENT_VERSION_NUMBER EVENT__NUMERIC_VERSION" .PP As event_get_version_number, but gives the version number of Libevent's headers\&. .SH "Typedef Documentation" .PP .SS "typedef void(* event_callback_fn) (\fBevutil_socket_t\fP, short, void *)" .PP A callback function for an event\&. It receives three arguments: .PP \fBParameters:\fP .RS 4 \fIfd\fP An fd or signal .br \fIevents\fP One or more EV_* flags .br \fIarg\fP A user-supplied argument\&. .RE .PP \fBSee also:\fP .RS 4 \fBevent_new()\fP .RE .PP .SS "typedef void(* event_fatal_cb) (int err)" .PP A function to be called if Libevent encounters a fatal internal error\&. .PP \fBSee also:\fP .RS 4 \fBevent_set_fatal_callback\fP .RE .PP .SS "typedef void(* event_finalize_callback_fn) (struct \fBevent\fP *, void *)" .PP Callback type for event_finalize and event_free_finalize()\&. THIS IS AN EXPERIMENTAL API\&. IT MIGHT CHANGE BEFORE THE LIBEVENT 2\&.1 SERIES BECOMES STABLE\&. .SS "typedef void(* event_log_cb) (int severity, const char *msg)" .PP A callback function used to intercept Libevent's log messages\&. .PP \fBSee also:\fP .RS 4 \fBevent_set_log_callback\fP .RE .PP .SH "Enumeration Type Documentation" .PP .SS "enum \fBevent_base_config_flag\fP" .PP A flag passed to \fBevent_config_set_flag()\fP\&. These flags change the behavior of an allocated \fBevent_base\fP\&. .PP \fBSee also:\fP .RS 4 \fBevent_config_set_flag()\fP, \fBevent_base_new_with_config()\fP, \fBevent_method_feature\fP .RE .PP .PP \fBEnumerator\fP .in +1c .TP \fB\fIEVENT_BASE_FLAG_NOLOCK \fP\fP Do not allocate a lock for the event base, even if we have locking set up\&. Setting this option will make it unsafe and nonfunctional to call functions on the base concurrently from multiple threads\&. .TP \fB\fIEVENT_BASE_FLAG_IGNORE_ENV \fP\fP Do not check the EVENT_* environment variables when configuring an \fBevent_base\fP\&. .TP \fB\fIEVENT_BASE_FLAG_STARTUP_IOCP \fP\fP Windows only: enable the IOCP dispatcher at startup\&. If this flag is set then \fBbufferevent_socket_new()\fP and evconn_listener_new() will use IOCP-backed implementations instead of the usual select-based one on Windows\&. .TP \fB\fIEVENT_BASE_FLAG_NO_CACHE_TIME \fP\fP Instead of checking the current time every time the event loop is ready to run timeout callbacks, check after each timeout callback\&. .TP \fB\fIEVENT_BASE_FLAG_EPOLL_USE_CHANGELIST \fP\fP If we are using the epoll backend, this flag says that it is safe to use Libevent's internal change-list code to batch up adds and deletes in order to try to do as few syscalls as possible\&. Setting this flag can make your code run faster, but it may trigger a Linux bug: it is not safe to use this flag if you have any fds cloned by dup() or its variants\&. Doing so will produce strange and hard-to-diagnose bugs\&. .PP This flag can also be activated by setting the EVENT_EPOLL_USE_CHANGELIST environment variable\&. .PP This flag has no effect if you wind up using a backend other than epoll\&. .TP \fB\fIEVENT_BASE_FLAG_PRECISE_TIMER \fP\fP Ordinarily, Libevent implements its time and timeout code using the fastest monotonic timer that we have\&. If this flag is set, however, we use less efficient more precise timer, assuming one is present\&. .SS "enum \fBevent_method_feature\fP" .PP A flag used to describe which features an \fBevent_base\fP (must) provide\&. Because of OS limitations, not every Libevent backend supports every possible feature\&. You can use this type with \fBevent_config_require_features()\fP to tell Libevent to only proceed if your \fBevent_base\fP implements a given feature, and you can receive this type from \fBevent_base_get_features()\fP to see which features are available\&. .PP \fBEnumerator\fP .in +1c .TP \fB\fIEV_FEATURE_ET \fP\fP Require an event method that allows edge-triggered events with EV_ET\&. .TP \fB\fIEV_FEATURE_O1 \fP\fP Require an event method where having one event triggered among many is [approximately] an O(1) operation\&. This excludes (for example) select and poll, which are approximately O(N) for N equal to the total number of possible events\&. .TP \fB\fIEV_FEATURE_FDS \fP\fP Require an event method that allows file descriptors as well as sockets\&. .TP \fB\fIEV_FEATURE_EARLY_CLOSE \fP\fP Require an event method that allows you to use EV_CLOSED to detect connection close without the necessity of reading all the pending data\&. Methods that do support EV_CLOSED may not be able to provide support on all kernel versions\&. .SH "Function Documentation" .PP .SS "EVENT2_EXPORT_SYMBOL void event_active (struct \fBevent\fP * ev, int res, short ncalls)" .PP Make an event active\&. You can use this function on a pending or a non-pending event to make it active, so that its callback will be run by \fBevent_base_dispatch()\fP or \fBevent_base_loop()\fP\&. .PP One common use in multithreaded programs is to wake the thread running \fBevent_base_loop()\fP from another thread\&. .PP \fBParameters:\fP .RS 4 \fIev\fP an event to make active\&. .br \fIres\fP a set of flags to pass to the event's callback\&. .br \fIncalls\fP an obsolete argument: this is ignored\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_add (struct \fBevent\fP * ev, const struct timeval * timeout)" .PP Add an event to the set of pending events\&. The function \fBevent_add()\fP schedules the execution of the event 'ev' when the condition specified by \fBevent_assign()\fP or \fBevent_new()\fP occurs, or when the time specified in timeout has elapesed\&. If atimeout is NULL, no timeout occurs and the function will only be called if a matching event occurs\&. The event in the ev argument must be already initialized by \fBevent_assign()\fP or \fBevent_new()\fP and may not be used in calls to \fBevent_assign()\fP until it is no longer pending\&. .PP If the event in the ev argument already has a scheduled timeout, calling \fBevent_add()\fP replaces the old timeout with the new one if tv is non-NULL\&. .PP \fBParameters:\fP .RS 4 \fIev\fP an event struct initialized via \fBevent_assign()\fP or \fBevent_new()\fP .br \fItimeout\fP the maximum amount of time to wait for the event, or NULL to wait forever .RE .PP \fBReturns:\fP .RS 4 0 if successful, or -1 if an error occurred .RE .PP \fBSee also:\fP .RS 4 \fBevent_del()\fP, \fBevent_assign()\fP, \fBevent_new()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_assign (struct \fBevent\fP *, struct \fBevent_base\fP *, \fBevutil_socket_t\fP, short, \fBevent_callback_fn\fP, void *)" .PP Prepare a new, already-allocated event structure to be added\&. The function \fBevent_assign()\fP prepares the event structure ev to be used in future calls to \fBevent_add()\fP and \fBevent_del()\fP\&. Unlike \fBevent_new()\fP, it doesn't allocate memory itself: it requires that you have already allocated a struct event, probably on the heap\&. Doing this will typically make your code depend on the size of the event structure, and thereby create incompatibility with future versions of Libevent\&. .PP The easiest way to avoid this problem is just to use \fBevent_new()\fP and \fBevent_free()\fP instead\&. .PP A slightly harder way to future-proof your code is to use \fBevent_get_struct_event_size()\fP to determine the required size of an event at runtime\&. .PP Note that it is NOT safe to call this function on an event that is active or pending\&. Doing so WILL corrupt internal data structures in Libevent, and lead to strange, hard-to-diagnose bugs\&. You \fIcan\fP use event_assign to change an existing event, but only if it is not active or pending! .PP The arguments for this function, and the behavior of the events that it makes, are as for \fBevent_new()\fP\&. .PP \fBParameters:\fP .RS 4 \fIev\fP an event struct to be modified .br \fIbase\fP the event base to which ev should be attached\&. .br \fIfd\fP the file descriptor to be monitored .br \fIevents\fP desired events to monitor; can be EV_READ and/or EV_WRITE .br \fIcallback\fP callback function to be invoked when the event occurs .br \fIcallback_arg\fP an argument to be passed to the callback function .RE .PP \fBReturns:\fP .RS 4 0 if success, or -1 on invalid arguments\&. .RE .PP \fBSee also:\fP .RS 4 \fBevent_new()\fP, \fBevent_add()\fP, \fBevent_del()\fP, \fBevent_base_once()\fP, \fBevent_get_struct_event_size()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL void event_base_active_by_fd (struct \fBevent_base\fP * base, \fBevutil_socket_t\fP fd, short events)" .PP Activates all pending events for the given fd and event mask\&. This function activates pending events only\&. Events which have not been added will not become active\&. .PP \fBParameters:\fP .RS 4 \fIbase\fP the \fBevent_base\fP on which to activate the events\&. .br \fIfd\fP An fd to active events on\&. .br \fIevents\fP One or more of EV_{READ,WRITE}\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL void event_base_active_by_signal (struct \fBevent_base\fP * base, int sig)" .PP Activates all pending signals with a given signal number\&. This function activates pending events only\&. Events which have not been added will not become active\&. .PP \fBParameters:\fP .RS 4 \fIbase\fP the \fBevent_base\fP on which to activate the events\&. .br \fIfd\fP The signal to active events on\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_dispatch (struct \fBevent_base\fP *)" .PP Event dispatching loop\&. This loop will run the event base until either there are no more pending or active, or until something calls \fBevent_base_loopbreak()\fP or \fBevent_base_loopexit()\fP\&. .PP \fBParameters:\fP .RS 4 \fIbase\fP the \fBevent_base\fP structure returned by \fBevent_base_new()\fP or \fBevent_base_new_with_config()\fP .RE .PP \fBReturns:\fP .RS 4 0 if successful, -1 if an error occurred, or 1 if we exited because no events were pending or active\&. .RE .PP \fBSee also:\fP .RS 4 \fBevent_base_loop()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL void event_base_dump_events (struct \fBevent_base\fP *, FILE *)" .PP Writes a human-readable description of all inserted and/or active events to a provided stdio stream\&. This is intended for debugging; its format is not guaranteed to be the same between libevent versions\&. .PP \fBParameters:\fP .RS 4 \fIbase\fP An \fBevent_base\fP on which to scan the events\&. .br \fIoutput\fP A stdio file to write on\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_foreach_event (struct \fBevent_base\fP * base, \fBevent_base_foreach_event_cb\fP fn, void * arg)" .PP Iterate over all added or active events events in an event loop, and invoke a given callback on each one\&. The callback must not call any function that modifies the event base, that modifies any event in the event base, or that adds or removes any event to the event base\&. Doing so is unsupported and will lead to undefined behavior -- likely, to crashes\&. .PP \fBevent_base_foreach_event()\fP holds a lock on the \fBevent_base()\fP for the whole time it's running: slow callbacks are not advisable\&. .PP Note that Libevent adds some events of its own to make pieces of its functionality work\&. You must not assume that the only events you'll encounter will be the ones you added yourself\&. .PP The callback function must return 0 to continue iteration, or some other integer to stop iterating\&. .PP \fBParameters:\fP .RS 4 \fIbase\fP An \fBevent_base\fP on which to scan the events\&. .br \fIfn\fP A callback function to receive the events\&. .br \fIarg\fP An argument passed to the callback function\&. .RE .PP \fBReturns:\fP .RS 4 0 if we iterated over every event, or the value returned by the callback function if the loop exited early\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL void event_base_free (struct \fBevent_base\fP *)" .PP Deallocate all memory associated with an \fBevent_base\fP, and free the base\&. Note that this function will not close any fds or free any memory passed to event_new as the argument to callback\&. .PP If there are any pending finalizer callbacks, this function will invoke them\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP an \fBevent_base\fP to be freed .RE .PP .SS "EVENT2_EXPORT_SYMBOL void event_base_free_nofinalize (struct \fBevent_base\fP *)" .PP As event_free, but do not run finalizers\&. THIS IS AN EXPERIMENTAL API\&. IT MIGHT CHANGE BEFORE THE LIBEVENT 2\&.1 SERIES BECOMES STABLE\&. .SS "EVENT2_EXPORT_SYMBOL int event_base_get_features (const struct \fBevent_base\fP * base)" .PP 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 .PP \fBSee also:\fP .RS 4 \fBevent_method_feature\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_get_max_events (struct \fBevent_base\fP *, unsigned int, int)" .PP Get the maximum number of events in a given \fBevent_base\fP as specified in the flags\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP the \fBevent_base\fP structure returned by \fBevent_base_new()\fP .br \fIflags\fP a bitwise combination of the kinds of events to aggregate counts for .br \fIclear\fP option used to reset the maximum count\&. .RE .PP \fBReturns:\fP .RS 4 the number of events specified in the flags .RE .PP .SS "EVENT2_EXPORT_SYMBOL const char* event_base_get_method (const struct \fBevent_base\fP *)" .PP Get the kernel event notification mechanism used by Libevent\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP the \fBevent_base\fP structure returned by \fBevent_base_new()\fP .RE .PP \fBReturns:\fP .RS 4 a string identifying the kernel event mechanism (kqueue, epoll, etc\&.) .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_get_npriorities (struct \fBevent_base\fP * eb)" .PP Get the number of different event priorities\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP the \fBevent_base\fP structure returned by \fBevent_base_new()\fP .RE .PP \fBReturns:\fP .RS 4 Number of different event priorities .RE .PP \fBSee also:\fP .RS 4 \fBevent_base_priority_init()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_get_num_events (struct \fBevent_base\fP *, unsigned int)" .PP Gets the number of events in \fBevent_base\fP, as specified in the flags\&. Since event base has some internal events added to make some of its functionalities work, EVENT_BASE_COUNT_ADDED may return more than the number of events you added using \fBevent_add()\fP\&. .PP If you pass EVENT_BASE_COUNT_ACTIVE and EVENT_BASE_COUNT_ADDED together, an active event will be counted twice\&. However, this might not be the case in future libevent versions\&. The return value is an indication of the work load, but the user shouldn't rely on the exact value as this may change in the future\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP the \fBevent_base\fP structure returned by \fBevent_base_new()\fP .br \fIflags\fP a bitwise combination of the kinds of events to aggregate counts for .RE .PP \fBReturns:\fP .RS 4 the number of events specified in the flags .RE .PP .SS "EVENT2_EXPORT_SYMBOL struct \fBevent\fP* event_base_get_running_event (struct \fBevent_base\fP * base)" .PP If called from within the callback for an event, returns that event\&. The behavior of this function is not defined when called from outside the callback function for an event\&. .SS "EVENT2_EXPORT_SYMBOL int event_base_gettimeofday_cached (struct \fBevent_base\fP * base, struct timeval * tv)" .PP 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\&. Generally, this value will only be cached while actually processing event callbacks, and may be very inaccuate if your callbacks take a long time to execute\&. .PP Returns 0 on success, negative on failure\&. .SS "EVENT2_EXPORT_SYMBOL int event_base_got_break (struct \fBevent_base\fP *)" .PP Checks if the event loop was told to abort immediately by \fBevent_base_loopbreak()\fP\&. This function will return true for an \fBevent_base\fP at every point after \fBevent_base_loopbreak()\fP is called, until the event loop is next entered\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP the \fBevent_base\fP structure returned by \fBevent_init()\fP .RE .PP \fBReturns:\fP .RS 4 true if \fBevent_base_loopbreak()\fP was called on this event base, or 0 otherwise .RE .PP \fBSee also:\fP .RS 4 \fBevent_base_loopbreak()\fP .PP \fBevent_base_got_exit()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_got_exit (struct \fBevent_base\fP *)" .PP Checks if the event loop was told to exit by \fBevent_base_loopexit()\fP\&. This function will return true for an \fBevent_base\fP at every point after \fBevent_loopexit()\fP is called, until the event loop is next entered\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP the \fBevent_base\fP structure returned by \fBevent_init()\fP .RE .PP \fBReturns:\fP .RS 4 true if \fBevent_base_loopexit()\fP was called on this event base, or 0 otherwise .RE .PP \fBSee also:\fP .RS 4 \fBevent_base_loopexit()\fP .PP \fBevent_base_got_break()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL const struct timeval* event_base_init_common_timeout (struct \fBevent_base\fP * base, const struct timeval * duration)" .PP Prepare an \fBevent_base\fP to use a large number of timeouts with the same duration\&. Libevent's default scheduling algorithm is optimized for having a large number of timeouts with their durations more or less randomly distributed\&. But if you have a large number of timeouts that all have the same duration (for example, if you have a large number of connections that all have a 10-second timeout), then you can improve Libevent's performance by telling Libevent about it\&. .PP To do this, call this function with the common duration\&. It will return a pointer to a different, opaque timeout value\&. (Don't depend on its actual contents!) When you use this timeout value in \fBevent_add()\fP, Libevent will schedule the event more efficiently\&. .PP (This optimization probably will not be worthwhile until you have thousands or tens of thousands of events with the same timeout\&.) .SS "EVENT2_EXPORT_SYMBOL int event_base_loop (struct \fBevent_base\fP *, int)" .PP Wait for events to become active, and run their callbacks\&. This is a more flexible version of \fBevent_base_dispatch()\fP\&. .PP By default, this loop will run the event base until either there are no more pending or active events, or until something calls \fBevent_base_loopbreak()\fP or \fBevent_base_loopexit()\fP\&. You can override this behavior with the 'flags' argument\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP the \fBevent_base\fP structure returned by \fBevent_base_new()\fP or \fBevent_base_new_with_config()\fP .br \fIflags\fP any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK .RE .PP \fBReturns:\fP .RS 4 0 if successful, -1 if an error occurred, or 1 if we exited because no events were pending or active\&. .RE .PP \fBSee also:\fP .RS 4 \fBevent_base_loopexit()\fP, \fBevent_base_dispatch()\fP, \fBEVLOOP_ONCE\fP, \fBEVLOOP_NONBLOCK\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_loopbreak (struct \fBevent_base\fP *)" .PP Abort the active \fBevent_base_loop()\fP immediately\&. \fBevent_base_loop()\fP will abort the loop after the next event is completed; \fBevent_base_loopbreak()\fP is typically invoked from this event's callback\&. This behavior is analogous to the 'break;' statement\&. .PP Subsequent invocations of \fBevent_base_loop()\fP will proceed normally\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP the \fBevent_base\fP structure returned by \fBevent_init()\fP .RE .PP \fBReturns:\fP .RS 4 0 if successful, or -1 if an error occurred .RE .PP \fBSee also:\fP .RS 4 \fBevent_base_loopexit()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_loopcontinue (struct \fBevent_base\fP *)" .PP Tell the active \fBevent_base_loop()\fP to scan for new events immediately\&. Calling this function makes the currently active \fBevent_base_loop()\fP start the loop over again (scanning for new events) after the current event callback finishes\&. If the event loop is not running, this function has no effect\&. .PP \fBevent_base_loopbreak()\fP is typically invoked from this event's callback\&. This behavior is analogous to the 'continue;' statement\&. .PP Subsequent invocations of event loop will proceed normally\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP the \fBevent_base\fP structure returned by \fBevent_init()\fP .RE .PP \fBReturns:\fP .RS 4 0 if successful, or -1 if an error occurred .RE .PP \fBSee also:\fP .RS 4 \fBevent_base_loopbreak()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_loopexit (struct \fBevent_base\fP *, const struct timeval *)" .PP Exit the event loop after the specified time\&. The next \fBevent_base_loop()\fP iteration after the given timer expires will complete normally (handling all queued events) then exit without blocking for events again\&. .PP Subsequent invocations of \fBevent_base_loop()\fP will proceed normally\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP the \fBevent_base\fP structure returned by \fBevent_init()\fP .br \fItv\fP the amount of time after which the loop should terminate, or NULL to exit after running all currently active events\&. .RE .PP \fBReturns:\fP .RS 4 0 if successful, or -1 if an error occurred .RE .PP \fBSee also:\fP .RS 4 \fBevent_base_loopbreak()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL struct \fBevent_base\fP* event_base_new (void)" .PP Create and return a new \fBevent_base\fP to use with the rest of Libevent\&. .PP \fBReturns:\fP .RS 4 a new \fBevent_base\fP on success, or NULL on failure\&. .RE .PP \fBSee also:\fP .RS 4 \fBevent_base_free()\fP, \fBevent_base_new_with_config()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL struct \fBevent_base\fP* event_base_new_with_config (const struct \fBevent_config\fP *)" .PP Initialize the event API\&. Use \fBevent_base_new_with_config()\fP to initialize a new event base, taking the specified configuration under consideration\&. The configuration object can currently be used to avoid certain event notification mechanisms\&. .PP \fBParameters:\fP .RS 4 \fIcfg\fP the event configuration object .RE .PP \fBReturns:\fP .RS 4 an initialized \fBevent_base\fP that can be used to registering events, or NULL if no event base can be created with the requested \fBevent_config\fP\&. .RE .PP \fBSee also:\fP .RS 4 \fBevent_base_new()\fP, \fBevent_base_free()\fP, \fBevent_init()\fP, \fBevent_assign()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_once (struct \fBevent_base\fP *, \fBevutil_socket_t\fP, short, \fBevent_callback_fn\fP, void *, const struct timeval *)" .PP Schedule a one-time event\&. The function \fBevent_base_once()\fP is similar to \fBevent_new()\fP\&. However, it schedules a callback to be called exactly once, and does not require the caller to prepare an event structure\&. .PP Note that in Libevent 2\&.0 and earlier, if the event is never triggered, the internal memory used to hold it will never be freed\&. In Libevent 2\&.1, the internal memory will get freed by \fBevent_base_free()\fP if the event is never triggered\&. The 'arg' value, however, will not get freed in either case--you'll need to free that on your own if you want it to go away\&. .PP \fBParameters:\fP .RS 4 \fIbase\fP an \fBevent_base\fP .br \fIfd\fP a file descriptor to monitor, or -1 for no fd\&. .br \fIevents\fP \fBevent(s)\fP to monitor; can be any of EV_READ | EV_WRITE, or EV_TIMEOUT .br \fIcallback\fP callback function to be invoked when the event occurs .br \fIarg\fP an argument to be passed to the callback function .br \fItimeout\fP the maximum amount of time to wait for the event\&. NULL makes an EV_READ/EV_WRITE event make forever; NULL makes an EV_TIMEOUT event succees immediately\&. .RE .PP \fBReturns:\fP .RS 4 0 if successful, or -1 if an error occurred .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_priority_init (struct \fBevent_base\fP *, int)" .PP Set the number of different event priorities\&. By default Libevent schedules all active events with the same priority\&. However, some time it is desirable to process some events with a higher priority than others\&. For that reason, Libevent supports strict priority queues\&. Active events with a lower priority are always processed before events with a higher priority\&. .PP The number of different priorities can be set initially with the \fBevent_base_priority_init()\fP function\&. This function should be called before the first call to \fBevent_base_dispatch()\fP\&. The \fBevent_priority_set()\fP function can be used to assign a priority to an event\&. By default, Libevent assigns the middle priority to all events unless their priority is explicitly set\&. .PP Note that urgent-priority events can starve less-urgent events: after running all urgent-priority callbacks, Libevent checks for more urgent events again, before running less-urgent events\&. Less-urgent events will not have their callbacks run until there are no events more urgent than them that want to be active\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP the \fBevent_base\fP structure returned by \fBevent_base_new()\fP .br \fInpriorities\fP the maximum number of priorities .RE .PP \fBReturns:\fP .RS 4 0 if successful, or -1 if an error occurred .RE .PP \fBSee also:\fP .RS 4 \fBevent_priority_set()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_set (struct \fBevent_base\fP *, struct \fBevent\fP *)" .PP Associate a different event base with an event\&. The event to be associated must not be currently active or pending\&. .PP \fBParameters:\fP .RS 4 \fIeb\fP the event base .br \fIev\fP the event .RE .PP \fBReturns:\fP .RS 4 0 on success, -1 on failure\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_base_update_cache_time (struct \fBevent_base\fP * base)" .PP Update cached_tv in the 'base' to the current time\&. You can use this function is useful for selectively increasing the accuracy of the cached time value in 'base' during callbacks that take a long time to execute\&. .PP This function has no effect if the base is currently not in its event loop, or if timeval caching is disabled via EVENT_BASE_FLAG_NO_CACHE_TIME\&. .PP \fBReturns:\fP .RS 4 0 on success, -1 on failure .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_config_avoid_method (struct \fBevent_config\fP * cfg, const char * method)" .PP Enters an event method that should be avoided into the configuration\&. This can be used to avoid event mechanisms that do not support certain file descriptor types, or for debugging to avoid certain event mechanisms\&. An application can make use of multiple event bases to accommodate incompatible file descriptor types\&. .PP \fBParameters:\fP .RS 4 \fIcfg\fP the event configuration object .br \fImethod\fP the name of the event method to avoid .RE .PP \fBReturns:\fP .RS 4 0 on success, -1 on failure\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL void event_config_free (struct \fBevent_config\fP * cfg)" .PP Deallocates all memory associated with an event configuration object\&. .PP \fBParameters:\fP .RS 4 \fIcfg\fP the event configuration object to be freed\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL struct \fBevent_config\fP* event_config_new (void)" .PP Allocates a new event configuration object\&. The event configuration object can be used to change the behavior of an event base\&. .PP \fBReturns:\fP .RS 4 an \fBevent_config\fP object that can be used to store configuration, or NULL if an error is encountered\&. .RE .PP \fBSee also:\fP .RS 4 \fBevent_base_new_with_config()\fP, \fBevent_config_free()\fP, \fBevent_config\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_config_require_features (struct \fBevent_config\fP * cfg, int feature)" .PP Enters a required event method feature that the application demands\&. Note that not every feature or combination of features is supported on every platform\&. Code that requests features should be prepared to handle the case where \fBevent_base_new_with_config()\fP returns NULL, as in: .PP .nf event_config_require_features(cfg, EV_FEATURE_ET); base = event_base_new_with_config(cfg); if (base == NULL) { // We can't get edge-triggered behavior here\&. event_config_require_features(cfg, 0); base = event_base_new_with_config(cfg); } .fi .PP .PP \fBParameters:\fP .RS 4 \fIcfg\fP the event configuration object .br \fIfeature\fP a bitfield of one or more event_method_feature values\&. Replaces values from previous calls to this function\&. .RE .PP \fBReturns:\fP .RS 4 0 on success, -1 on failure\&. .RE .PP \fBSee also:\fP .RS 4 \fBevent_method_feature\fP, \fBevent_base_new_with_config()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_config_set_flag (struct \fBevent_config\fP * cfg, int flag)" .PP Sets one or more flags to configure what parts of the eventual \fBevent_base\fP will be initialized, and how they'll work\&. .PP \fBSee also:\fP .RS 4 event_base_config_flags, \fBevent_base_new_with_config()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_config_set_max_dispatch_interval (struct \fBevent_config\fP * cfg, const struct timeval * max_interval, int max_callbacks, int min_priority)" .PP Record an interval and/or a number of callbacks after which the event base should check for new events\&. By default, the event base will run as many events are as activated at the higest activated priority before checking for new events\&. If you configure it by setting max_interval, it will check the time after each callback, and not allow more than max_interval to elapse before checking for new events\&. If you configure it by setting max_callbacks to a value >= 0, it will run no more than max_callbacks callbacks before checking for new events\&. .PP This option can decrease the latency of high-priority events, and avoid priority inversions where multiple low-priority events keep us from polling for high-priority events, but at the expense of slightly decreasing the throughput\&. Use it with caution! .PP \fBParameters:\fP .RS 4 \fIcfg\fP The \fBevent_base\fP configuration object\&. .br \fImax_interval\fP An interval after which Libevent should stop running callbacks and check for more events, or NULL if there should be no such interval\&. .br \fImax_callbacks\fP A number of callbacks after which Libevent should stop running callbacks and check for more events, or -1 if there should be no such limit\&. .br \fImin_priority\fP A priority below which max_interval and max_callbacks should not be enforced\&. If this is set to 0, they are enforced for events of every priority; if it's set to 1, they're enforced for events of priority 1 and above, and so on\&. .RE .PP \fBReturns:\fP .RS 4 0 on success, -1 on failure\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_config_set_num_cpus_hint (struct \fBevent_config\fP * cfg, int cpus)" .PP 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\&. .PP \fBParameters:\fP .RS 4 \fIcfg\fP the event configuration object .br \fIcpus\fP the number of cpus .RE .PP \fBReturns:\fP .RS 4 0 on success, -1 on failure\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL void event_debug_unassign (struct \fBevent\fP *)" .PP 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\&. .PP This function must only be called on a non-added event\&. .PP \fBSee also:\fP .RS 4 \fBevent_enable_debug_mode()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_del (struct \fBevent\fP *)" .PP Remove an event from the set of monitored events\&. The function \fBevent_del()\fP will cancel the event in the argument ev\&. If the event has already executed or has never been added the call will have no effect\&. .PP \fBParameters:\fP .RS 4 \fIev\fP an event struct to be removed from the working set .RE .PP \fBReturns:\fP .RS 4 0 if successful, or -1 if an error occurred .RE .PP \fBSee also:\fP .RS 4 \fBevent_add()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_del_block (struct \fBevent\fP * ev)" .PP As \fBevent_del()\fP, but always blocks while the event's callback is running in another thread, even if the event was constructed with the EV_FINALIZE flag\&. THIS IS AN EXPERIMENTAL API\&. IT MIGHT CHANGE BEFORE THE LIBEVENT 2\&.1 SERIES BECOMES STABLE\&. .SS "EVENT2_EXPORT_SYMBOL int event_del_noblock (struct \fBevent\fP * ev)" .PP As \fBevent_del()\fP, but never blocks while the event's callback is running in another thread, even if the event was constructed without the EV_FINALIZE flag\&. THIS IS AN EXPERIMENTAL API\&. IT MIGHT CHANGE BEFORE THE LIBEVENT 2\&.1 SERIES BECOMES STABLE\&. .SS "EVENT2_EXPORT_SYMBOL void event_enable_debug_logging (ev_uint32_t which)" .PP Turn on debugging logs and have them sent to the default log handler\&. This is a global setting; if you are going to call it, you must call this before any calls that create an event-base\&. You must call it before any multithreaded use of Libevent\&. .PP Debug logs are verbose\&. .PP \fBParameters:\fP .RS 4 \fIwhich\fP Controls which debug messages are turned on\&. This option is unused for now; for forward compatibility, you must pass in the constant 'EVENT_DBG_ALL' to turn debugging logs on, or 'EVENT_DBG_NONE' to turn debugging logs off\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL void event_enable_debug_mode (void)" .PP 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\&. .PP Debug mode can currently catch the following errors: An event is re-assigned while it is added Any function is called on a non-assigned event .PP Note that debugging mode uses memory to track every event that has been initialized (via event_assign, event_set, or event_new) but not yet released (via event_free or event_debug_unassign)\&. If you want to use debug mode, and you find yourself running out of memory, you will need to use event_debug_unassign to explicitly stop tracking events that are no longer considered set-up\&. .PP \fBSee also:\fP .RS 4 \fBevent_debug_unassign()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL void event_free (struct \fBevent\fP *)" .PP Deallocate a struct event * returned by \fBevent_new()\fP\&. If the event is pending or active, first make it non-pending and non-active\&. .SS "EVENT2_EXPORT_SYMBOL void event_get_assignment (const struct \fBevent\fP * event, struct \fBevent_base\fP ** base_out, \fBevutil_socket_t\fP * fd_out, short * events_out, \fBevent_callback_fn\fP * callback_out, void ** arg_out)" .PP Extract \fIall\fP of arguments given to construct a given event\&. The \fBevent_base\fP is copied into *base_out, the fd is copied into *fd_out, and so on\&. .PP If any of the '_out' arguments is NULL, it will be ignored\&. .SS "EVENT2_EXPORT_SYMBOL int event_get_priority (const struct \fBevent\fP * ev)" .PP Return the priority of an event\&. .PP \fBSee also:\fP .RS 4 \fBevent_priority_init()\fP, \fBevent_get_priority()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL size_t event_get_struct_event_size (void)" .PP Return the size of struct event that the Libevent library was compiled with\&. This will be NO GREATER than sizeof(struct event) if you're running with the same version of Libevent that your application was built with, but otherwise might not\&. .PP Note that it might be SMALLER than sizeof(struct event) if some future version of Libevent adds extra padding to the end of struct event\&. We might do this to help ensure ABI-compatibility between different versions of Libevent\&. .SS "EVENT2_EXPORT_SYMBOL const char** event_get_supported_methods (void)" .PP Gets all event notification mechanisms supported by Libevent\&. This functions returns the event mechanism in order preferred by Libevent\&. Note that this list will include all backends that Libevent has compiled-in support for, and will not necessarily check your OS to see whether it has the required resources\&. .PP \fBReturns:\fP .RS 4 an array with pointers to the names of support methods\&. The end of the array is indicated by a NULL pointer\&. If an error is encountered NULL is returned\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL const char* event_get_version (void)" .PP Get the Libevent version\&. Note that this will give you the version of the library that you're currently linked against, not the version of the headers that you've compiled against\&. .PP \fBReturns:\fP .RS 4 a string containing the version number of Libevent .RE .PP .SS "EVENT2_EXPORT_SYMBOL ev_uint32_t event_get_version_number (void)" .PP Return a numeric representation of Libevent's version\&. Note that this will give you the version of the library that you're currently linked against, not the version of the headers you've used to compile\&. .PP The format uses one byte each for the major, minor, and patchlevel parts of the version number\&. The low-order byte is unused\&. For example, version 2\&.0\&.1-alpha has a numeric representation of 0x02000100 .SS "EVENT2_EXPORT_SYMBOL int event_initialized (const struct \fBevent\fP * ev)" .PP Test if an event structure might be initialized\&. The \fBevent_initialized()\fP function can be used to check if an event has been initialized\&. .PP Warning: This function is only useful for distinguishing a a zeroed-out piece of memory from an initialized event, it can easily be confused by uninitialized memory\&. Thus, it should ONLY be used to distinguish an initialized event from zero\&. .PP \fBParameters:\fP .RS 4 \fIev\fP an event structure to be tested .RE .PP \fBReturns:\fP .RS 4 1 if the structure might be initialized, or 0 if it has not been initialized .RE .PP .SS "EVENT2_EXPORT_SYMBOL struct \fBevent\fP* event_new (struct \fBevent_base\fP *, \fBevutil_socket_t\fP, short, \fBevent_callback_fn\fP, void *)" .PP Allocate and asssign a new event structure, ready to be added\&. The function \fBevent_new()\fP returns a new event that can be used in future calls to \fBevent_add()\fP and \fBevent_del()\fP\&. The fd and events arguments determine which conditions will trigger the event; the callback and callback_arg arguments tell Libevent what to do when the event becomes active\&. .PP If events contains one of EV_READ, EV_WRITE, or EV_READ|EV_WRITE, then fd is a file descriptor or socket that should get monitored for readiness to read, readiness to write, or readiness for either operation (respectively)\&. If events contains EV_SIGNAL, then fd is a signal number to wait for\&. If events contains none of those flags, then the event can be triggered only by a timeout or by manual activation with \fBevent_active()\fP: In this case, fd must be -1\&. .PP The EV_PERSIST flag can also be passed in the events argument: it makes \fBevent_add()\fP persistent until \fBevent_del()\fP is called\&. .PP The EV_ET flag is compatible with EV_READ and EV_WRITE, and supported only by certain backends\&. It tells Libevent to use edge-triggered events\&. .PP The EV_TIMEOUT flag has no effect here\&. .PP It is okay to have multiple events all listening on the same fds; but they must either all be edge-triggered, or all not be edge triggerd\&. .PP When the event becomes active, the event loop will run the provided callbuck function, with three arguments\&. The first will be the provided fd value\&. The second will be a bitfield of the events that triggered: EV_READ, EV_WRITE, or EV_SIGNAL\&. Here the EV_TIMEOUT flag indicates that a timeout occurred, and EV_ET indicates that an edge-triggered event occurred\&. The third event will be the callback_arg pointer that you provide\&. .PP \fBParameters:\fP .RS 4 \fIbase\fP the event base to which the event should be attached\&. .br \fIfd\fP the file descriptor or signal to be monitored, or -1\&. .br \fIevents\fP desired events to monitor: bitfield of EV_READ, EV_WRITE, EV_SIGNAL, EV_PERSIST, EV_ET\&. .br \fIcallback\fP callback function to be invoked when the event occurs .br \fIcallback_arg\fP an argument to be passed to the callback function .RE .PP \fBReturns:\fP .RS 4 a newly allocated struct event that must later be freed with \fBevent_free()\fP\&. .RE .PP \fBSee also:\fP .RS 4 \fBevent_free()\fP, \fBevent_add()\fP, \fBevent_del()\fP, \fBevent_assign()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_pending (const struct \fBevent\fP * ev, short events, struct timeval * tv)" .PP Checks if a specific event is pending or scheduled\&. .PP \fBParameters:\fP .RS 4 \fIev\fP an event struct previously passed to \fBevent_add()\fP .br \fIevents\fP the requested event type; any of EV_TIMEOUT|EV_READ| EV_WRITE|EV_SIGNAL .br \fItv\fP if this field is not NULL, and the event has a timeout, this field is set to hold the time at which the timeout will expire\&. .RE .PP \fBReturns:\fP .RS 4 true if the event is pending on any of the events in 'what', (that is to say, it has been added), or 0 if the event is not added\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_priority_set (struct \fBevent\fP *, int)" .PP Assign a priority to an event\&. .PP \fBParameters:\fP .RS 4 \fIev\fP an event struct .br \fIpriority\fP the new priority to be assigned .RE .PP \fBReturns:\fP .RS 4 0 if successful, or -1 if an error occurred .RE .PP \fBSee also:\fP .RS 4 \fBevent_priority_init()\fP, \fBevent_get_priority()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_reinit (struct \fBevent_base\fP * base)" .PP Reinitialize the event base after a fork\&. Some event mechanisms do not survive across fork\&. The event base needs to be reinitialized with the \fBevent_reinit()\fP function\&. .PP \fBParameters:\fP .RS 4 \fIbase\fP the event base that needs to be re-initialized .RE .PP \fBReturns:\fP .RS 4 0 if successful, or -1 if some events could not be re-added\&. .RE .PP \fBSee also:\fP .RS 4 \fBevent_base_new()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL int event_remove_timer (struct \fBevent\fP * ev)" .PP Remove a timer from a pending event without removing the event itself\&. If the event has a scheduled timeout, this function unschedules it but leaves the event otherwise pending\&. .PP \fBParameters:\fP .RS 4 \fIev\fP an event struct initialized via \fBevent_assign()\fP or \fBevent_new()\fP .RE .PP \fBReturns:\fP .RS 4 0 on success, or -1 if an error occurrect\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL void* event_self_cbarg (void)" .PP Return a value used to specify that the event itself must be used as the callback argument\&. The function \fBevent_new()\fP takes a callback argument which is passed to the event's callback function\&. To specify that the argument to be passed to the callback function is the event that \fBevent_new()\fP returns, pass in the return value of \fBevent_self_cbarg()\fP as the callback argument for \fBevent_new()\fP\&. .PP For example: .PP .nf struct event *ev = event_new(base, sock, events, callback, event_self_cbarg()); .fi .PP .PP For consistency with \fBevent_new()\fP, it is possible to pass the return value of this function as the callback argument for \fBevent_assign()\fP -- this achieves the same result as passing the event in directly\&. .PP \fBReturns:\fP .RS 4 a value to be passed as the callback argument to \fBevent_new()\fP or \fBevent_assign()\fP\&. .RE .PP \fBSee also:\fP .RS 4 \fBevent_new()\fP, \fBevent_assign()\fP .RE .PP .SS "EVENT2_EXPORT_SYMBOL void event_set_fatal_callback (\fBevent_fatal_cb\fP cb)" .PP Override Libevent's behavior in the event of a fatal internal error\&. By default, Libevent will call exit(1) if a programming error makes it impossible to continue correct operation\&. This function allows you to supply another callback instead\&. Note that if the function is ever invoked, something is wrong with your program, or with Libevent: any subsequent calls to Libevent may result in undefined behavior\&. .PP Libevent will (almost) always log an EVENT_LOG_ERR message before calling this function; look at the last log message to see why Libevent has died\&. .SS "EVENT2_EXPORT_SYMBOL void event_set_log_callback (\fBevent_log_cb\fP cb)" .PP Redirect Libevent's log messages\&. .PP \fBParameters:\fP .RS 4 \fIcb\fP a function taking two arguments: an integer severity between EVENT_LOG_DEBUG and EVENT_LOG_ERR, and a string\&. If cb is NULL, then the default log is used\&. .RE .PP NOTE: The function you provide \fImust not\fP call any other libevent functionality\&. Doing so can produce undefined behavior\&. .SS "EVENT2_EXPORT_SYMBOL void event_set_mem_functions (void *(*)(size_t sz) malloc_fn, void *(*)(void *ptr, size_t sz) realloc_fn, void(*)(void *ptr) free_fn)" .PP Override the functions that Libevent uses for memory management\&. Usually, Libevent uses the standard libc functions malloc, realloc, and free to allocate memory\&. Passing replacements for those functions to \fBevent_set_mem_functions()\fP overrides this behavior\&. .PP Note that all memory returned from Libevent will be allocated by the replacement functions rather than by malloc() and realloc()\&. Thus, if you have replaced those functions, it will not be appropriate to free() memory that you get from Libevent\&. Instead, you must use the free_fn replacement that you provided\&. .PP Note also that if you are going to call this function, you should do so before any call to any Libevent function that does allocation\&. Otherwise, those funtions will allocate their memory using malloc(), but then later free it using your provided free_fn\&. .PP \fBParameters:\fP .RS 4 \fImalloc_fn\fP A replacement for malloc\&. .br \fIrealloc_fn\fP A replacement for realloc .br \fIfree_fn\fP A replacement for free\&. .RE .PP .SS "EVENT2_EXPORT_SYMBOL void libevent_global_shutdown (void)" .PP Release up all globally-allocated resources allocated by Libevent\&. This function does not free developer-controlled resources like event_bases, events, bufferevents, listeners, and so on\&. It only releases resources like global locks that there is no other way to free\&. .PP It is not actually necessary to call this function before exit: every resource that it frees would be released anyway on exit\&. It mainly exists so that resource-leak debugging tools don't see Libevent as holding resources at exit\&. .PP You should only call this function when no other Libevent functions will be invoked -- e\&.g\&., when cleanly exiting a program\&. .SH "Author" .PP Generated automatically by Doxygen for libevent from the source code\&.