OpenMPI  0.1.1
event.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3  * Copyright (c) 2007-2010 Niels Provos and Nick Mathewson
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef _EVENT2_EVENT_H_
28 #define _EVENT2_EVENT_H_
29 
30 /**
31  @mainpage
32 
33  @section intro Introduction
34 
35  Libevent is an event notification library for developing scalable network
36  servers. The Libevent API provides a mechanism to execute a callback
37  function when a specific event occurs on a file descriptor or after a
38  timeout has been reached. Furthermore, Libevent also support callbacks due
39  to signals or regular timeouts.
40 
41  Libevent is meant to replace the event loop found in event driven network
42  servers. An application just needs to call event_dispatch() and then add or
43  remove events dynamically without having to change the event loop.
44 
45 
46  Currently, Libevent supports /dev/poll, kqueue(2), select(2), poll(2),
47  epoll(4), and evports. The internal event mechanism is completely
48  independent of the exposed event API, and a simple update of Libevent can
49  provide new functionality without having to redesign the applications. As a
50  result, Libevent allows for portable application development and provides
51  the most scalable event notification mechanism available on an operating
52  system. Libevent can also be used for multithreaded programs. Libevent
53  should compile on Linux, *BSD, Mac OS X, Solaris and, Windows.
54 
55  @section usage Standard usage
56 
57  Every program that uses Libevent must inclurde the <event2/event.h>
58  header, and pass the -levent flag to the linker. (You can instead link
59  -levent_core if you only want the main event and buffered IO-based code,
60  and don't want to link any protocol code.)
61 
62  @section setup Library setup
63 
64  Before you call any other Libevent functions, you need to set up the
65  library. If you're going to use Libevent from multiple threads in a
66  multithreaded application, you need to initialize thread support --
67  typically by using evthread_use_pthreads() or
68  evthread_use_windows_threads(). See <event2/thread.h> for more
69  information.
70 
71  This is also the point where you can replace Libevent's memory
72  management functions with event_set_mem_functions, and enable debug mode
73  with event_enable_debug_mode().
74 
75  @section base Creating an event base
76 
77  Next, you need to create an event_base structure, using event_base_new()
78  or event_base_new_with_config(). The event_base is responsible for
79  keeping track of which events are "pending" (that is to say, being
80  watched to see if they become active) and which events are "active".
81  Every event is associated with a single event_base.
82 
83  @section event Event notification
84 
85  For each file descriptor that you wish to monitor, you must create an
86  event structure with event_new(). (You may also declare an event
87  structure and call event_assign() to initialize the members of the
88  structure.) To enable notification, you add the structure to the list
89  of monitored events by calling event_add(). The event structure must
90  remain allocated as long as it is active, so it should generally be
91  allocated on the heap.
92 
93  @section loop Dispaching evets.
94 
95  Finally, you call event_base_dispatch() to loop and dispatch events.
96  You can also use event_base_loop() for more fine-grained control.
97 
98  Currently, only one thread can be dispatching a given event_base at a
99  time. If you want to run events in multiple threads at once, you can
100  either have a single event_base whose events add work to a work queue,
101  or you can create multiple event_base objects.
102 
103  @section bufferevent I/O Buffers
104 
105  Libevent provides a buffered I/O abstraction on top of the regular event
106  callbacks. This abstraction is called a bufferevent. A bufferevent
107  provides input and output buffers that get filled and drained
108  automatically. The user of a buffered event no longer deals directly
109  with the I/O, but instead is reading from input and writing to output
110  buffers.
111 
112  Once initialized via bufferevent_socket_new(), the bufferevent structure
113  can be used repeatedly with bufferevent_enable() and
114  bufferevent_disable(). Instead of reading and writing directly to a
115  socket, you would call bufferevent_read() and bufferevent_write().
116 
117  When read enabled the bufferevent will try to read from the file descriptor
118  and call the read callback. The write callback is executed whenever the
119  output buffer is drained below the write low watermark, which is 0 by
120  default.
121 
122  See <event2/bufferevent*.h> for more information.
123 
124  @section timers Timers
125 
126  Libevent can also be used to create timers that invoke a callback after a
127  certain amount of time has expired. The evtimer_new() function returns
128  an event struct to use as a timer. To activate the timer, call
129  evtimer_add(). Timers can be deactivated by calling evtimer_del().
130 
131  @section evdns Asynchronous DNS resolution
132 
133  Libevent provides an asynchronous DNS resolver that should be used instead
134  of the standard DNS resolver functions. See the <event2/dns.h>
135  functions for more detail.
136 
137  @section evhttp Event-driven HTTP servers
138 
139  Libevent provides a very simple event-driven HTTP server that can be
140  embedded in your program and used to service HTTP requests.
141 
142  To use this capability, you need to include the <event2/http.h> header in your
143  program. See that header for more information.
144 
145  @section evrpc A framework for RPC servers and clients
146 
147  Libevent provides a framework for creating RPC servers and clients. It
148  takes care of marshaling and unmarshaling all data structures.
149 
150  @section api API Reference
151 
152  To browse the complete documentation of the libevent API, click on any of
153  the following links.
154 
155  event2/event.h
156  The primary libevent header
157 
158  event2/thread.h
159  Functions for use by multithreaded programs
160 
161  event2/buffer.h and event2/bufferevent.h
162  Buffer management for network reading and writing
163 
164  event2/util.h
165  Utility functions for portable nonblocking network code
166 
167  event2/dns.h
168  Asynchronous DNS resolution
169 
170  event2/http.h
171  An embedded libevent-based HTTP server
172 
173  event2/rpc.h
174  A framework for creating RPC servers and clients
175 
176  */
177 
178 /** @file event2/event.h
179 
180  Core functions for waiting for and receiving events, and using event bases.
181 */
182 
183 #ifdef __cplusplus
184 extern "C" {
185 #endif
186 
187 /**** OMPI CHANGE ****/
188 #include "opal_rename.h"
189 /**** END OMPI CHANGE ****/
190 
191 #include <event2/event-config.h>
192 #ifdef _EVENT_HAVE_SYS_TYPES_H
193 #include <sys/types.h>
194 #endif
195 #ifdef _EVENT_HAVE_SYS_TIME_H
196 #include <sys/time.h>
197 #endif
198 
199 #include <stdio.h>
200 
201 /* For int types. */
202 #include <event2/util.h>
203 
204 /**
205  * Structure to hold information and state for a Libevent dispatch loop.
206  *
207  * The event_base lies at the center of Libevent; every application will
208  * have one. It keeps track of all pending and active events, and
209  * notifies your application of the active ones.
210  *
211  * This is an opaque structure; you can allocate one using
212  * event_base_new() or event_base_new_with_config().
213  *
214  * @see event_base_new(), event_base_free(), event_base_loop(),
215  * event_base_new_with_config()
216  */
217 struct event_base
218 #ifdef _EVENT_IN_DOXYGEN
219 {/*Empty body so that doxygen will generate documentation here.*/}
220 #endif
221 ;
222 
223 /**
224  * @struct event
225  *
226  * Structure to represent a single event.
227  *
228  * An event can have some underlying condition it represents: a socket
229  * becoming readable or writeable (or both), or a signal becoming raised.
230  * (An event that represents no underlying condition is still useful: you
231  * can use one to implement a timer, or to communicate between threads.)
232  *
233  * Generally, you can create events with event_new(), then make them
234  * pending with event_add(). As your event_base runs, it will run the
235  * callbacks of an events whose conditions are triggered. When you
236  * longer want the event, free it with event_free().
237  *
238  * In more depth:
239  *
240  * An event may be "pending" (one whose condition we are watching),
241  * "active" (one whose condition has triggered and whose callback is about
242  * to run), neither, or both. Events come into existence via
243  * event_assign() or event_new(), and are then neither active nor pending.
244  *
245  * To make an event pending, pass it to event_add(). When doing so, you
246  * can also set a timeout for the event.
247  *
248  * Events become active during an event_base_loop() call when either their
249  * condition has triggered, or when their timeout has elapsed. You can
250  * also activate an event manually using event_active(). The even_base
251  * loop will run the callbacks of active events; after it has done so, it
252  * marks them as no longer active.
253  *
254  * You can make an event non-pending by passing it to event_del(). This
255  * also makes the event non-active.
256  *
257  * Events can be "persistent" or "non-persistent". A non-persistent event
258  * becomes non-pending as soon as it is triggered: thus, it only runs at
259  * most once per call to event_add(). A persistent event remains pending
260  * even when it becomes active: you'll need to event_del() it manually in
261  * order to make it non-pending. When a persistent event with a timeout
262  * becomes active, its timeout is reset: this means you can use persistent
263  * events to implement periodic timeouts.
264  *
265  * This should be treated as an opaque structure; you should never read or
266  * write any of its fields directly. For backward compatibility with old
267  * code, it is defined in the event2/event_struct.h header; including this
268  * header may make your code incompatible with other versions of Libevent.
269  *
270  * @see event_new(), event_free(), event_assign(), event_get_assignment(),
271  * event_add(), event_del(), event_active(), event_pending(),
272  * event_get_fd(), event_get_base(), event_get_events(),
273  * event_get_callback(), event_get_callback_arg(),
274  * event_priority_set()
275  */
276 struct event
277 #ifdef _EVENT_IN_DOXYGEN
278 {/*Empty body so that doxygen will generate documentation here.*/}
279 #endif
280 ;
281 
282 /**
283  * Configuration for an event_base.
284  *
285  * There are many options that can be used to alter the behavior and
286  * implementation of an event_base. To avoid having to pass them all in a
287  * complex many-argument constructor, we provide an abstract data type
288  * wrhere you set up configation information before passing it to
289  * event_base_new_with_config().
290  *
291  * @see event_config_new(), event_config_free(), event_base_new_with_config(),
292  * event_config_avoid_method(), event_config_require_features(),
293  * event_config_set_flag(), event_config_set_num_cpus_hint()
294  */
295 struct event_config
296 #ifdef _EVENT_IN_DOXYGEN
297 {/*Empty body so that doxygen will generate documentation here.*/}
298 #endif
299 ;
300 
301 /**
302  * Enable some relatively expensive debugging checks in Libevent that
303  * would normally be turned off. Generally, these checks cause code that
304  * would otherwise crash mysteriously to fail earlier with an assertion
305  * failure. Note that this method MUST be called before any events or
306  * event_bases have been created.
307  *
308  * Debug mode can currently catch the following errors:
309  * An event is re-assigned while it is added
310  * Any function is called on a non-assigned event
311  *
312  * Note that debugging mode uses memory to track every event that has been
313  * initialized (via event_assign, event_set, or event_new) but not yet
314  * released (via event_free or event_debug_unassign). If you want to use
315  * debug mode, and you find yourself running out of memory, you will need
316  * to use event_debug_unassign to explicitly stop tracking events that
317  * are no longer considered set-up.
318  *
319  * @see event_debug_unassign()
320  */
321 void event_enable_debug_mode(void);
322 
323 /**** OMPI CHANGE ****/
324 void event_set_debug_output(int output);
325 /**** END OMPI CHANGE ****/
326 
327 /**
328  * When debugging mode is enabled, informs Libevent that an event should no
329  * longer be considered as assigned. When debugging mode is not enabled, does
330  * nothing.
331  *
332  * This function must only be called on a non-added event.
333  *
334  * @see event_enable_debug_mode()
335  */
336 void event_debug_unassign(struct event *);
337 
338 /**
339  * Create and return a new event_base to use with the rest of Libevent.
340  *
341  * @return a new event_base on success, or NULL on failure.
342  *
343  * @see event_base_free(), event_base_new_with_config()
344  */
345 struct event_base *event_base_new(void);
346 
347 /**
348  Reinitialize the event base after a fork
349 
350  Some event mechanisms do not survive across fork. The event base needs
351  to be reinitialized with the event_reinit() function.
352 
353  @param base the event base that needs to be re-initialized
354  @return 0 if successful, or -1 if some events could not be re-added.
355  @see event_base_new()
356 */
357 int event_reinit(struct event_base *base);
358 
359 /**
360  Event dispatching loop
361 
362  This loop will run the event base until either there are no more added
363  events, or until something calls event_base_loopbreak() or
364  event_base_loopexit().
365 
366  @param base the event_base structure returned by event_base_new() or
367  event_base_new_with_config()
368  @return 0 if successful, -1 if an error occurred, or 1 if no events were
369  registered.
370  @see event_base_loop()
371  */
372 int event_base_dispatch(struct event_base *);
373 
374 /**
375  Get the kernel event notification mechanism used by Libevent.
376 
377  @param eb the event_base structure returned by event_base_new()
378  @return a string identifying the kernel event mechanism (kqueue, epoll, etc.)
379  */
380 const char *event_base_get_method(const struct event_base *);
381 
382 /**
383  Gets all event notification mechanisms supported by Libevent.
384 
385  This functions returns the event mechanism in order preferred by
386  Libevent. Note that this list will include all backends that
387  Libevent has compiled-in support for, and will not necessarily check
388  your OS to see whether it has the required resources.
389 
390  @return an array with pointers to the names of support methods.
391  The end of the array is indicated by a NULL pointer. If an
392  error is encountered NULL is returned.
393 */
394 const char **event_get_supported_methods(void);
395 
396 /**
397  Allocates a new event configuration object.
398 
399  The event configuration object can be used to change the behavior of
400  an event base.
401 
402  @return an event_config object that can be used to store configuration, or
403  NULL if an error is encountered.
404  @see event_base_new_with_config(), event_config_free(), event_config
405 */
406 struct event_config *event_config_new(void);
407 
408 /**
409  Deallocates all memory associated with an event configuration object
410 
411  @param cfg the event configuration object to be freed.
412 */
413 void event_config_free(struct event_config *cfg);
414 
415 /**
416  Enters an event method that should be avoided into the configuration.
417 
418  This can be used to avoid event mechanisms that do not support certain
419  file descriptor types, or for debugging to avoid certain event
420  mechanisms. An application can make use of multiple event bases to
421  accommodate incompatible file descriptor types.
422 
423  @param cfg the event configuration object
424  @param method the name of the event method to avoid
425  @return 0 on success, -1 on failure.
426 */
427 int event_config_avoid_method(struct event_config *cfg, const char *method);
429 /**
430  A flag used to describe which features an event_base (must) provide.
431 
432  Because of OS limitations, not every Libevent backend supports every
433  possible feature. You can use this type with
434  event_config_require_features() to tell Libevent to only proceed if your
435  event_base implements a given feature, and you can receive this type from
436  event_base_get_features() to see which features are available.
437 */
439  /** Require an event method that allows edge-triggered events with EV_ET. */
440  EV_FEATURE_ET = 0x01,
441  /** Require an event method where having one event triggered among
442  * many is [approximately] an O(1) operation. This excludes (for
443  * example) select and poll, which are approximately O(N) for N
444  * equal to the total number of possible events. */
445  EV_FEATURE_O1 = 0x02,
446  /** Require an event method that allows file descriptors as well as
447  * sockets. */
448  EV_FEATURE_FDS = 0x04
449 };
451 /**
452  A flag passed to event_config_set_flag().
454  These flags change the behavior of an allocated event_base.
455 
456  @see event_config_set_flag(), event_base_new_with_config(),
457  event_method_feature
458  */
460  /** Do not allocate a lock for the event base, even if we have
461  locking set up. */
462  EVENT_BASE_FLAG_NOLOCK = 0x01,
463  /** Do not check the EVENT_* environment variables when configuring
464  an event_base */
466  /** Windows only: enable the IOCP dispatcher at startup
467 
468  If this flag is set then bufferevent_socket_new() and
469  evconn_listener_new() will use IOCP-backed implementations
470  instead of the usual select-based one on Windows.
471  */
473  /** Instead of checking the current time every time the event loop is
474  ready to run timeout callbacks, check after each timeout callback.
475  */
477 
478  /** If we are using the epoll backend, this flag says that it is
479  safe to use Libevent's internal change-list code to batch up
480  adds and deletes in order to try to do as few syscalls as
481  possible. Setting this flag can make your code run faster, but
482  it may trigger a Linux bug: it is not safe to use this flag
483  if you have any fds cloned by dup() or its variants. Doing so
484  will produce strange and hard-to-diagnose bugs.
485 
486  This flag can also be activated by settnig the
487  EVENT_EPOLL_USE_CHANGELIST environment variable.
488 
489  This flag has no effect if you wind up using a backend other than
490  epoll.
491  */
493 };
494 
495 /**
496  Return a bitmask of the features implemented by an event base. This
497  will be a bitwise OR of one or more of the values of
498  event_method_feature
499 
500  @see event_method_feature
501  */
502 int event_base_get_features(const struct event_base *base);
503 
504 /**
505  Enters a required event method feature that the application demands.
506 
507  Note that not every feature or combination of features is supported
508  on every platform. Code that requests features should be prepared
509  to handle the case where event_base_new_with_config() returns NULL, as in:
510  <pre>
511  event_config_require_features(cfg, EV_FEATURE_ET);
512  base = event_base_new_with_config(cfg);
513  if (base == NULL) {
514  // We can't get edge-triggered behavior here.
515  event_config_require_features(cfg, 0);
516  base = event_base_new_with_config(cfg);
517  }
518  </pre>
519 
520  @param cfg the event configuration object
521  @param feature a bitfield of one or more event_method_feature values.
522  Replaces values from previous calls to this function.
523  @return 0 on success, -1 on failure.
524  @see event_method_feature, event_base_new_with_config()
525 */
526 int event_config_require_features(struct event_config *cfg, int feature);
527 
528 /**
529  * Sets one or more flags to configure what parts of the eventual event_base
530  * will be initialized, and how they'll work.
531  *
532  * @see event_base_config_flags, event_base_new_with_config()
533  **/
534 int event_config_set_flag(struct event_config *cfg, int flag);
535 
536 /**
537  * Records a hint for the number of CPUs in the system. This is used for
538  * tuning thread pools, etc, for optimal performance. In Libevent 2.0,
539  * it is only on Windows, and only when IOCP is in use.
540  *
541  * @param cfg the event configuration object
542  * @param cpus the number of cpus
543  * @return 0 on success, -1 on failure.
544  */
545 int event_config_set_num_cpus_hint(struct event_config *cfg, int cpus);
546 
547 /**
548  Initialize the event API.
549 
550  Use event_base_new_with_config() to initialize a new event base, taking
551  the specified configuration under consideration. The configuration object
552  can currently be used to avoid certain event notification mechanisms.
553 
554  @param cfg the event configuration object
555  @return an initialized event_base that can be used to registering events,
556  or NULL if no event base can be created with the requested event_config.
557  @see event_base_new(), event_base_free(), event_init(), event_assign()
558 */
559 struct event_base *event_base_new_with_config(const struct event_config *);
560 
561 /**
562  Deallocate all memory associated with an event_base, and free the base.
563 
564  Note that this function will not close any fds or free any memory passed
565  to event_new as the argument to callback.
566 
567  @param eb an event_base to be freed
568  */
569 void event_base_free(struct event_base *);
570 
571 /** @name Log severities
572  */
573 /**@{*/
574 #define _EVENT_LOG_DEBUG 0
575 #define _EVENT_LOG_MSG 1
576 #define _EVENT_LOG_WARN 2
577 #define _EVENT_LOG_ERR 3
578 /**@}*/
579 
580 /**
581  A callback function used to intercept Libevent's log messages.
582 
583  @see event_set_log_callback
584  */
585 typedef void (*event_log_cb)(int severity, const char *msg);
586 /**
587  Redirect Libevent's log messages.
588 
589  @param cb a function taking two arguments: an integer severity between
590  _EVENT_LOG_DEBUG and _EVENT_LOG_ERR, and a string. If cb is NULL,
591  then the default log is used.
592 
593  NOTE: The function you provide *must not* call any other libevent
594  functionality. Doing so can produce undefined behavior.
595  */
597 
598 /**
599  A function to be called if Libevent encounters a fatal internal error.
600 
601  @see event_set_fatal_callback
602  */
603 typedef void (*event_fatal_cb)(int err);
604 
605 /**
606  Override Libevent's behavior in the event of a fatal internal error.
607 
608  By default, Libevent will call exit(1) if a programming error makes it
609  impossible to continue correct operation. This function allows you to supply
610  another callback instead. Note that if the function is ever invoked,
611  something is wrong with your program, or with Libevent: any subsequent calls
612  to Libevent may result in undefined behavior.
613 
614  Libevent will (almost) always log an _EVENT_LOG_ERR message before calling
615  this function; look at the last log message to see why Libevent has died.
616  */
618 
619 /**
620  Associate a different event base with an event.
621 
622  The event to be associated must not be currently active or pending.
623 
624  @param eb the event base
625  @param ev the event
626  @return 0 on success, -1 on failure.
627  */
628 int event_base_set(struct event_base *, struct event *);
629 
630 /** @name Loop flags
631 
632  These flags control the behavior of event_base_loop().
633  */
634 /**@{*/
635 /** Block until we have an active event, then exit once all active events
636  * have had their callbacks run. */
637 #define EVLOOP_ONCE 0x01
638 /** Do not block: see which events are ready now, run the callbacks
639  * of the highest-priority ones, then exit. */
640 #define EVLOOP_NONBLOCK 0x02
641 /**@}*/
642 
643 /**
644  Wait for events to become active, and run their callbacks.
645 
646  This is a more flexible version of event_base_dispatch().
647 
648  By default, this loop will run the event base until either there are no more
649  added events, or until something calls event_base_loopbreak() or
650  evenet_base_loopexit(). You can override this behavior with the 'flags'
651  argument.
652 
653  @param eb the event_base structure returned by event_base_new() or
654  event_base_new_with_config()
655  @param flags any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK
656  @return 0 if successful, -1 if an error occurred, or 1 if no events were
657  registered.
658  @see event_base_loopexit(), event_base_dispatch(), EVLOOP_ONCE,
659  EVLOOP_NONBLOCK
660  */
661 int event_base_loop(struct event_base *, int);
662 
663 /**
664  Exit the event loop after the specified time
665 
666  The next event_base_loop() iteration after the given timer expires will
667  complete normally (handling all queued events) then exit without
668  blocking for events again.
669 
670  Subsequent invocations of event_base_loop() will proceed normally.
671 
672  @param eb the event_base structure returned by event_init()
673  @param tv the amount of time after which the loop should terminate,
674  or NULL to exit after running all currently active events.
675  @return 0 if successful, or -1 if an error occurred
676  @see event_base_loopbreak()
677  */
678 int event_base_loopexit(struct event_base *, const struct timeval *);
679 
680 /**
681  Abort the active event_base_loop() immediately.
682 
683  event_base_loop() will abort the loop after the next event is completed;
684  event_base_loopbreak() is typically invoked from this event's callback.
685  This behavior is analogous to the "break;" statement.
686 
687  Subsequent invocations of event_loop() will proceed normally.
688 
689  @param eb the event_base structure returned by event_init()
690  @return 0 if successful, or -1 if an error occurred
691  @see event_base_loopexit()
692  */
693 int event_base_loopbreak(struct event_base *);
694 
695 /**
696  Checks if the event loop was told to exit by event_loopexit().
697 
698  This function will return true for an event_base at every point after
699  event_loopexit() is called, until the event loop is next entered.
700 
701  @param eb the event_base structure returned by event_init()
702  @return true if event_base_loopexit() was called on this event base,
703  or 0 otherwise
704  @see event_base_loopexit()
705  @see event_base_got_break()
706  */
707 int event_base_got_exit(struct event_base *);
708 
709 /**
710  Checks if the event loop was told to abort immediately by event_loopbreak().
711 
712  This function will return true for an event_base at every point after
713  event_loopbreak() is called, until the event loop is next entered.
714 
715  @param eb the event_base structure returned by event_init()
716  @return true if event_base_loopbreak() was called on this event base,
717  or 0 otherwise
718  @see event_base_loopbreak()
719  @see event_base_got_exit()
720  */
721 int event_base_got_break(struct event_base *);
723 /**
724  * @name event flags
725  *
726  * Flags to pass to event_new(), event_assign(), event_pending(), and
727  * anything else with an argument of the form "short events"
728  */
729 /**@{*/
730 /** Indicates that a timeout has occurred. It's not necessary to pass
731  * this flag to event_for new()/event_assign() to get a timeout. */
732 #define EV_TIMEOUT 0x01
733 /** Wait for a socket or FD to become readable */
734 #define EV_READ 0x02
735 /** Wait for a socket or FD to become writeable */
736 #define EV_WRITE 0x04
737 /** Wait for a POSIX signal to be raised*/
738 #define EV_SIGNAL 0x08
739 /**
740  * Persistent event: won't get removed automatically when activated.
741  *
742  * When a persistent event with a timeout becomes activated, its timeout
743  * is reset to 0.
744  */
745 #define EV_PERSIST 0x10
746 /** Select edge-triggered behavior, if supported by the backend. */
747 #define EV_ET 0x20
748 /**@}*/
749 
750 /**
751  @name evtimer_* macros
752 
753  Aliases for working with one-shot timer events */
754 /**@{*/
755 #define evtimer_assign(ev, b, cb, arg) \
756  event_assign((ev), (b), -1, 0, (cb), (arg))
757 #define evtimer_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg))
758 #define evtimer_add(ev, tv) event_add((ev), (tv))
759 #define evtimer_del(ev) event_del(ev)
760 #define evtimer_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv))
761 #define evtimer_initialized(ev) event_initialized(ev)
762 /**@}*/
763 
764 /**
765  @name evsignal_* macros
766 
767  Aliases for working with signal events
768  */
769 /**@{*/
770 #define evsignal_add(ev, tv) event_add((ev), (tv))
771 #define evsignal_assign(ev, b, x, cb, arg) \
772  event_assign((ev), (b), (x), EV_SIGNAL|EV_PERSIST, cb, (arg))
773 #define evsignal_new(b, x, cb, arg) \
774  event_new((b), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
775 #define evsignal_del(ev) event_del(ev)
776 #define evsignal_pending(ev, tv) event_pending((ev), EV_SIGNAL, (tv))
777 #define evsignal_initialized(ev) event_initialized(ev)
778 /**@}*/
780 /**
781  A callback function for an event.
782 
783  It receives three arguments:
784 
785  @param fd An fd or signal
786  @param events One or more EV_* flags
787  @param arg A user-supplied argument.
788 
789  @see event_new()
790  */
791 typedef void (*event_callback_fn)(evutil_socket_t, short, void *);
792 
793 /**
794  Allocate and asssign a new event structure, ready to be added.
795 
796  The function event_new() returns a new event that can be used in
797  future calls to event_add() and event_del(). The fd and events
798  arguments determine which conditions will trigger the event; the
799  callback and callback_arg arguments tell Libevent what to do when the
800  event becomes active.
801 
802  If events contains one of EV_READ, EV_WRITE, or EV_READ|EV_WRITE, then
803  fd is a file descriptor or socket that should get monitored for
804  readiness to read, readiness to write, or readiness for either operation
805  (respectively). If events contains EV_SIGNAL, then fd is a signal
806  number to wait for. If events contains none of those flags, then the
807  event can be triggered only by a timeout or by manual activation with
808  event_active(): In this case, fd must be -1.
809 
810  The EV_PERSIST flag can also be passed in the events argument: it makes
811  event_add() persistent until event_del() is called.
812 
813  The EV_ET flag is compatible with EV_READ and EV_WRITE, and supported
814  only by certain backends. It tells Libevent to use edge-triggered
815  events.
816 
817  The EV_TIMEOUT flag has no effect here.
818 
819  It is okay to have multiple events all listening on the same fds; but
820  they must either all be edge-triggered, or all not be edge triggerd.
821 
822  When the event becomes active, the event loop will run the provided
823  callbuck function, with three arguments. The first will be the provided
824  fd value. The second will be a bitfield of the events that triggered:
825  EV_READ, EV_WRITE, or EV_SIGNAL. Here the EV_TIMEOUT flag indicates
826  that a timeout occurred, and EV_ET indicates that an edge-triggered
827  event occurred. The third event will be the callback_arg pointer that
828  you provide.
829 
830  @param base the event base to which the event should be attached.
831  @param fd the file descriptor or signal to be monitored, or -1.
832  @param events desired events to monitor: bitfield of EV_READ, EV_WRITE,
833  EV_SIGNAL, EV_PERSIST, EV_ET.
834  @param callback callback function to be invoked when the event occurs
835  @param callback_arg an argument to be passed to the callback function
836 
837  @return a newly allocated struct event that must later be freed with
838  event_free().
839  @see event_free(), event_add(), event_del(), event_assign()
840  */
841 struct event *event_new(struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
842 
843 
844 /**
845  Prepare a new, already-allocated event structure to be added.
846 
847  The function event_assign() prepares the event structure ev to be used
848  in future calls to event_add() and event_del(). Unlike event_new(), it
849  doesn't allocate memory itself: it requires that you have already
850  allocated a struct event, probably on the heap. Doing this will
851  typically make your code depend on the size of the event structure, and
852  thereby create incompatibility with future versions of Libevent.
853 
854  The easiest way to avoid this problem is just to use event_new() and
855  event_free() instead.
856 
857  A slightly harder way to future-proof your code is to use
858  event_get_struct_event_size() to determine the required size of an event
859  at runtime.
860 
861  Note that it is NOT safe to call this function on an event that is
862  active or pending. Doing so WILL corrupt internal data structures in
863  Libevent, and lead to strange, hard-to-diagnose bugs. You _can_ use
864  event_assign to change an existing event, but only if it is not active
865  or pending!
866 
867  The arguments for this function, and the behavior of the events that it
868  makes, are as for event_new().
869 
870  @param ev an event struct to be modified
871  @param base the event base to which ev should be attached.
872  @param fd the file descriptor to be monitored
873  @param events desired events to monitor; can be EV_READ and/or EV_WRITE
874  @param callback callback function to be invoked when the event occurs
875  @param callback_arg an argument to be passed to the callback function
876 
877  @return 0 if success, or -1 on invalid arguments.
878 
879  @see event_new(), event_add(), event_del(), event_base_once(),
880  event_get_struct_event_size()
881  */
882 int event_assign(struct event *, struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
883 
884 /**
885  Deallocate a struct event * returned by event_new().
886 
887  If the event is pending or active, first make it non-pending and
888  non-active.
889  */
890 void event_free(struct event *);
891 
892 /**
893  Schedule a one-time event
894 
895  The function event_base_once() is similar to event_set(). However, it
896  schedules a callback to be called exactly once, and does not require the
897  caller to prepare an event structure.
898 
899  Note that in Libevent 2.0 and earlier, if the event is never triggered,
900  the internal memory used to hold it will never be freed. This may be
901  fixed in a later version of Libevent.
902 
903  @param base an event_base
904  @param fd a file descriptor to monitor, or -1 for no fd.
905  @param events event(s) to monitor; can be any of EV_READ |
906  EV_WRITE, or EV_TIMEOUT
907  @param callback callback function to be invoked when the event occurs
908  @param arg an argument to be passed to the callback function
909  @param timeout the maximum amount of time to wait for the event. NULL
910  makes an EV_READ/EV_WRITE event make forever; NULL makes an
911  EV_TIMEOUT event succees immediately.
912  @return 0 if successful, or -1 if an error occurred
913  */
914 int event_base_once(struct event_base *, evutil_socket_t, short, event_callback_fn, void *, const struct timeval *);
915 
916 /**
917  Add an event to the set of pending events.
918 
919  The function event_add() schedules the execution of the ev event when the
920  event specified in event_assign()/event_new() occurs, or when the time
921  specified in timeout has elapesed. If atimeout is NULL, no timeout
922  occurs and the function will only be
923  called if a matching event occurs. The event in the
924  ev argument must be already initialized by event_assign() or event_new()
925  and may not be used
926  in calls to event_assign() until it is no longer pending.
927 
928  If the event in the ev argument already has a scheduled timeout, calling
929  event_add() replaces the old timeout with the new one, or clears the old
930  timeout if the timeout argument is NULL.
931 
932  @param ev an event struct initialized via event_set()
933  @param timeout the maximum amount of time to wait for the event, or NULL
934  to wait forever
935  @return 0 if successful, or -1 if an error occurred
936  @see event_del(), event_assign(), event_new()
937  */
938 int event_add(struct event *ev, const struct timeval *timeout);
939 
940 /**
941  Remove an event from the set of monitored events.
942 
943  The function event_del() will cancel the event in the argument ev. If the
944  event has already executed or has never been added the call will have no
945  effect.
946 
947  @param ev an event struct to be removed from the working set
948  @return 0 if successful, or -1 if an error occurred
949  @see event_add()
950  */
951 int event_del(struct event *);
952 
953 
954 /**
955  Make an event active.
956 
957  You can use this function on a pending or a non-pending event to make it
958  active, so that its callback will be run by event_base_dispatch() or
959  event_base_loop().
960 
961  One common use in multithreaded programs is to wake the thread running
962  event_base_loop() from another thread.
963 
964  @param ev an event to make active.
965  @param res a set of flags to pass to the event's callback.
966  @param ncalls an obsolete argument: this is ignored.
967  **/
968 void event_active(struct event *ev, int res, short ncalls);
969 
970 /**
971  Checks if a specific event is pending or scheduled.
972 
973  @param ev an event struct previously passed to event_add()
974  @param events the requested event type; any of EV_TIMEOUT|EV_READ|
975  EV_WRITE|EV_SIGNAL
976  @param tv if this field is not NULL, and the event has a timeout,
977  this field is set to hold the time at which the timeout will
978  expire.
979 
980  @return true if the event is pending on any of the events in 'what', (that
981  is to say, it has been added), or 0 if the event is not added.
982  */
983 int event_pending(const struct event *ev, short events, struct timeval *tv);
984 
985 
986 /**
987  Test if an event structure might be initialized.
988 
989  The event_initialized() function can be used to check if an event has been
990  initialized.
991 
992  Warning: This function is only useful for distinguishing a a zeroed-out
993  piece of memory from an initialized event, it can easily be confused by
994  uninitialized memory. Thus, it should ONLY be used to distinguish an
995  initialized event from zero.
996 
997  @param ev an event structure to be tested
998  @return 1 if the structure might be initialized, or 0 if it has not been
999  initialized
1000  */
1001 int event_initialized(const struct event *ev);
1002 
1003 /**
1004  Get the signal number assigned to a signal event
1005 */
1006 #define event_get_signal(ev) ((int)event_get_fd(ev))
1007 
1008 /**
1009  Get the socket or signal assigned to an event, or -1 if the event has
1010  no socket.
1011 */
1012 evutil_socket_t event_get_fd(const struct event *ev);
1013 
1014 /**
1015  Get the event_base associated with an event.
1016 */
1017 struct event_base *event_get_base(const struct event *ev);
1018 
1019 /**
1020  Return the events (EV_READ, EV_WRITE, etc) assigned to an event.
1021 */
1022 short event_get_events(const struct event *ev);
1023 
1024 /**
1025  Return the callback assigned to an event.
1026 */
1027 event_callback_fn event_get_callback(const struct event *ev);
1028 
1029 /**
1030  Return the callback argument assigned to an event.
1031 */
1032 void *event_get_callback_arg(const struct event *ev);
1033 
1034 /**
1035  Extract _all_ of arguments given to construct a given event. The
1036  event_base is copied into *base_out, the fd is copied into *fd_out, and so
1037  on.
1038 
1039  If any of the "_out" arguments is NULL, it will be ignored.
1040  */
1041 void event_get_assignment(const struct event *event,
1042  struct event_base **base_out, evutil_socket_t *fd_out, short *events_out,
1043  event_callback_fn *callback_out, void **arg_out);
1044 
1045 /**
1046  Return the size of struct event that the Libevent library was compiled
1047  with.
1048 
1049  This will be NO GREATER than sizeof(struct event) if you're running with
1050  the same version of Libevent that your application was built with, but
1051  otherwise might not.
1052 
1053  Note that it might be SMALLER than sizeof(struct event) if some future
1054  version of Libevent adds extra padding to the end of struct event.
1055  We might do this to help ensure ABI-compatibility between different
1056  versions of Libevent.
1057  */
1058 size_t event_get_struct_event_size(void);
1059 
1060 /**
1061  Get the Libevent version.
1062 
1063  Note that this will give you the version of the library that you're
1064  currently linked against, not the version of the headers that you've
1065  compiled against.
1066 
1067  @return a string containing the version number of Libevent
1068 */
1069 const char *event_get_version(void);
1070 
1071 /**
1072  Return a numeric representation of Libevent's version.
1074  Note that this will give you the version of the library that you're
1075  currently linked against, not the version of the headers you've used to
1076  compile.
1077 
1078  The format uses one byte each for the major, minor, and patchlevel parts of
1079  the version number. The low-order byte is unused. For example, version
1080  2.0.1-alpha has a numeric representation of 0x02000100
1081 */
1082 ev_uint32_t event_get_version_number(void);
1083 
1084 /** As event_get_version, but gives the version of Libevent's headers. */
1085 #define LIBEVENT_VERSION _EVENT_VERSION
1086 /** As event_get_version_number, but gives the version number of Libevent's
1087  * headers. */
1088 #define LIBEVENT_VERSION_NUMBER _EVENT_NUMERIC_VERSION
1089 
1090 /** Largest number of priorities that Libevent can support. */
1091 #define EVENT_MAX_PRIORITIES 256
1092 /**
1093  Set the number of different event priorities
1094 
1095  By default Libevent schedules all active events with the same priority.
1096  However, some time it is desirable to process some events with a higher
1097  priority than others. For that reason, Libevent supports strict priority
1098  queues. Active events with a lower priority are always processed before
1099  events with a higher priority.
1100 
1101  The number of different priorities can be set initially with the
1102  event_base_priority_init() function. This function should be called
1103  before the first call to event_base_dispatch(). The
1104  event_priority_set() function can be used to assign a priority to an
1105  event. By default, Libevent assigns the middle priority to all events
1106  unless their priority is explicitly set.
1107 
1108  Note that urgent-priority events can starve less-urgent events: after
1109  running all urgent-priority callbacks, Libevent checks for more urgent
1110  events again, before running less-urgent events. Less-urgent events
1111  will not have their callbacks run until there are no events more urgent
1112  than them that want to be active.
1113 
1114  @param eb the event_base structure returned by event_base_new()
1115  @param npriorities the maximum number of priorities
1116  @return 0 if successful, or -1 if an error occurred
1117  @see event_priority_set()
1118  */
1119 int event_base_priority_init(struct event_base *, int);
1120 
1121 /**
1122  Assign a priority to an event.
1123 
1124  @param ev an event struct
1125  @param priority the new priority to be assigned
1126  @return 0 if successful, or -1 if an error occurred
1127  @see event_priority_init()
1128  */
1129 int event_priority_set(struct event *, int);
1130 
1131 /**
1132  Prepare an event_base to use a large number of timeouts with the same
1133  duration.
1134 
1135  Libevent's default scheduling algorithm is optimized for having a large
1136  number of timeouts with their durations more or less randomly
1137  distributed. But if you have a large number of timeouts that all have
1138  the same duration (for example, if you have a large number of
1139  connections that all have a 10-second timeout), then you can improve
1140  Libevent's performance by telling Libevent about it.
1141 
1142  To do this, call this function with the common duration. It will return a
1143  pointer to a different, opaque timeout value. (Don't depend on its actual
1144  contents!) When you use this timeout value in event_add(), Libevent will
1145  schedule the event more efficiently.
1146 
1147  (This optimization probably will not be worthwhile until you have thousands
1148  or tens of thousands of events with the same timeout.)
1149  */
1150 const struct timeval *event_base_init_common_timeout(struct event_base *base,
1151  const struct timeval *duration);
1152 
1153 #if !defined(_EVENT_DISABLE_MM_REPLACEMENT) || defined(_EVENT_IN_DOXYGEN)
1154 /**
1155  Override the functions that Libevent uses for memory management.
1156 
1157  Usually, Libevent uses the standard libc functions malloc, realloc, and
1158  free to allocate memory. Passing replacements for those functions to
1159  event_set_mem_functions() overrides this behavior.
1160 
1161  Note that all memory returned from Libevent will be allocated by the
1162  replacement functions rather than by malloc() and realloc(). Thus, if you
1163  have replaced those functions, it will not be appropriate to free() memory
1164  that you get from Libevent. Instead, you must use the free_fn replacement
1165  that you provided.
1166 
1167  Note also that if you are going to call this function, you should do so
1168  before any call to any Libevent function that does allocation.
1169  Otherwise, those funtions will allocate their memory using malloc(), but
1170  then later free it using your provided free_fn.
1171 
1172  @param malloc_fn A replacement for malloc.
1173  @param realloc_fn A replacement for realloc
1174  @param free_fn A replacement for free.
1175  **/
1177  void *(*malloc_fn)(size_t sz),
1178  void *(*realloc_fn)(void *ptr, size_t sz),
1179  void (*free_fn)(void *ptr));
1180 /** This definition is present if Libevent was built with support for
1181  event_set_mem_functions() */
1182 #define EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
1183 #endif
1184 
1185 void event_base_dump_events(struct event_base *, FILE *);
1186 
1187 /** Sets 'tv' to the current time (as returned by gettimeofday()),
1188  looking at the cached value in 'base' if possible, and calling
1189  gettimeofday() or clock_gettime() as appropriate if there is no
1190  cached time.
1191 
1192  Generally, this value will only be cached while actually
1193  processing event callbacks, and may be very inaccuate if your
1194  callbacks take a long time to execute.
1195 
1196  Returns 0 on success, negative on failure.
1197  */
1199  struct timeval *tv);
1200 
1201 #ifdef __cplusplus
1202 }
1203 #endif
1204 
1205 #endif /* _EVENT2_EVENT_H_ */
int event_pending(const struct event *ev, short events, struct timeval *tv)
Checks if a specific event is pending or scheduled.
Definition: event.c:1826
Require an event method where having one event triggered among many is [approximately] an O(1) operat...
Definition: event.h:433
int event_config_require_features(struct event_config *cfg, int feature)
Enters a required event method feature that the application demands.
Definition: event.c:974
int event_reinit(struct event_base *base)
Reinitialize the event base after a fork.
Definition: event.c:799
int event_base_got_break(struct event_base *)
Checks if the event loop was told to abort immediately by event_loopbreak().
Definition: event.c:1483
const char * event_base_get_method(const struct event_base *)
Get the kernel event notification mechanism used by Libevent.
Definition: event.c:1428
void event_base_free(struct event_base *)
Deallocate all memory associated with an event_base, and free the base.
Definition: event.c:691
Internal structure: describes the configuration we want for an event_base that we're about to allocat...
Definition: event-internal.h:296
void event_enable_debug_mode(void)
Enable some relatively expensive debugging checks in Libevent that would normally be turned off...
Definition: event.c:514
Require an event method that allows file descriptors as well as sockets.
Definition: event.h:436
const char * event_get_version(void)
Get the Libevent version.
Definition: event.c:2598
int event_config_set_flag(struct event_config *cfg, int flag)
Sets one or more flags to configure what parts of the eventual event_base will be initialized...
Definition: event.c:948
struct event_config * event_config_new(void)
Allocates a new event configuration object.
Definition: event.c:915
evutil_socket_t event_get_fd(const struct event *ev)
Get the socket or signal assigned to an event, or -1 if the event has no socket.
Definition: event.c:1889
Instead of checking the current time every time the event loop is ready to run timeout callbacks...
Definition: event.h:464
ev_uint32_t event_get_version_number(void)
Return a numeric representation of Libevent's version.
Definition: event.c:2604
void event_active(struct event *ev, int res, short ncalls)
Make an event active.
Definition: event.c:2246
Structure to represent a single event.
Definition: event_struct.h:87
int event_del(struct event *)
Remove an event from the set of monitored events.
Definition: event.c:2146
int event_base_loopbreak(struct event_base *)
Abort the active event_base_loop() immediately.
Definition: event.c:1464
void(* event_fatal_cb)(int err)
A function to be called if Libevent encounters a fatal internal error.
Definition: event.h:591
void * event_get_callback_arg(const struct event *ev)
Return the callback argument assigned to an event.
Definition: event.c:1917
void event_get_assignment(const struct event *event, struct 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 construct a given event.
Definition: event.c:1866
int event_assign(struct event *, struct event_base *, evutil_socket_t, short, event_callback_fn, void *)
Prepare a new, already-allocated event structure to be added.
Definition: event.c:1695
struct event_base * event_get_base(const struct event *ev)
Get the event_base associated with an event.
Definition: event.c:1896
int event_base_loop(struct event_base *, int)
Wait for events to become active, and run their callbacks.
Definition: event.c:1511
int event_base_got_exit(struct event_base *)
Checks if the event loop was told to exit by event_loopexit().
Definition: event.c:1493
int event_priority_set(struct event *, int)
Assign a priority to an event.
Definition: event.c:1807
#define evutil_socket_t
A type wide enough to hold the output of "socket()" or "accept()".
Definition: util.h:278
void event_set_log_callback(event_log_cb cb)
Redirect Libevent's log messages.
Definition: log.c:197
int event_base_get_features(const struct event_base *base)
Return a bitmask of the features implemented by an event base.
Definition: event.c:486
struct event * event_new(struct event_base *, evutil_socket_t, short, event_callback_fn, void *)
Allocate and asssign a new event structure, ready to be added.
Definition: event.c:1766
void(* event_log_cb)(int severity, const char *msg)
A callback function used to intercept Libevent's log messages.
Definition: event.h:573
const char ** event_get_supported_methods(void)
Gets all event notification mechanisms supported by Libevent.
Definition: event.c:883
const struct timeval * event_base_init_common_timeout(struct event_base *base, const struct timeval *duration)
Prepare an event_base to use a large number of timeouts with the same duration.
Definition: event.c:1167
struct event_base * event_base_new(void)
Create and return a new event_base to use with the rest of Libevent.
Definition: event.c:442
int event_base_loopexit(struct event_base *, const struct timeval *)
Exit the event loop after the specified time.
Definition: event.c:1451
void event_set_fatal_callback(event_fatal_cb cb)
Override Libevent's behavior in the event of a fatal internal error.
Definition: log.c:71
int event_base_priority_init(struct event_base *, int)
Set the number of different event priorities.
Definition: event.c:999
int event_config_avoid_method(struct event_config *cfg, const char *method)
Enters an event method that should be avoided into the configuration.
Definition: event.c:957
Common convenience functions for cross-platform portability and related socket manipulations.
void(* event_callback_fn)(evutil_socket_t, short, void *)
A callback function for an event.
Definition: event.h:779
event_base_config_flag
A flag passed to event_config_set_flag().
Definition: event.h:447
Windows only: enable the IOCP dispatcher at startup.
Definition: event.h:460
int event_add(struct event *ev, const struct timeval *timeout)
Add an event to the set of pending events.
Definition: event.c:1924
void event_free(struct event *)
Deallocate a struct event * returned by event_new().
Definition: event.c:1781
Do not allocate a lock for the event base, even if we have locking set up.
Definition: event.h:450
int event_base_dispatch(struct event_base *)
Event dispatching loop.
Definition: event.c:1422
int event_base_gettimeofday_cached(struct event_base *base, struct timeval *tv)
Sets 'tv' to the current time (as returned by gettimeofday()), looking at the cached value in 'base' ...
Definition: event.c:386
int event_base_set(struct event_base *, struct event *)
Associate a different event base with an event.
Definition: event.c:1742
Do not check the EVENT_* environment variables when configuring an event_base.
Definition: event.h:453
void event_config_free(struct event_config *cfg)
Deallocates all memory associated with an event configuration object.
Definition: event.c:936
int event_config_set_num_cpus_hint(struct event_config *cfg, int cpus)
Records a hint for the number of CPUs in the system.
Definition: event.c:984
void event_debug_unassign(struct event *)
When debugging mode is enabled, informs Libevent that an event should no longer be considered as assi...
Definition: event.c:1793
If we are using the epoll backend, this flag says that it is safe to use Libevent's internal change-l...
Definition: event.h:480
int event_initialized(const struct event *ev)
Test if an event structure might be initialized.
Definition: event.c:1857
short event_get_events(const struct event *ev)
Return the events (EV_READ, EV_WRITE, etc) assigned to an event.
Definition: event.c:1903
void event_set_mem_functions(void *(*malloc_fn)(size_t sz), void *(*realloc_fn)(void *ptr, size_t sz), void(*free_fn)(void *ptr))
Override the functions that Libevent uses for memory management.
Definition: event.c:2683
event_callback_fn event_get_callback(const struct event *ev)
Return the callback assigned to an event.
Definition: event.c:1910
Require an event method that allows edge-triggered events with EV_ET.
Definition: event.h:428
Definition: event-internal.h:167
event_method_feature
A flag used to describe which features an event_base (must) provide.
Definition: event.h:426
size_t event_get_struct_event_size(void)
Return the size of struct event that the Libevent library was compiled with.
Definition: event.c:1883
struct event_base * event_base_new_with_config(const struct event_config *)
Initialize the event API.
Definition: event.c:557
int event_base_once(struct event_base *, evutil_socket_t, short, event_callback_fn, void *, const struct timeval *)
Schedule a one-time event.
Definition: event.c:1648