2 * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3 * Copyright (c) 2007-2010 Niels Provos and Nick Mathewson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef _EVENT2_EVENT_H_
28 #define _EVENT2_EVENT_H_
30 /** @file event2/event.h
32 Core functions for waiting for and receiving events, and using event bases.
40 #include <event2/event-config.h>
41 #ifdef _EVENT_HAVE_SYS_TYPES_H
42 #include <sys/types.h>
44 #ifdef _EVENT_HAVE_SYS_TIME_H
51 #include <event2/util.h>
57 /** Enable some relatively expensive debugging checks in Libevent that would
58 * normally be turned off. Generally, these cause code that would otherwise
59 * crash mysteriously to fail earlier with an assertion failure. Note that
60 * this method MUST be called before any events or event_bases have been
63 * Debug mode can currently catch the following errors:
64 * An event is re-assigned while it is added
65 * Any function is called on a non-assigned event
67 * Note that debugging mode uses memory to track every event that has been
68 * initialized (via event_assign, event_set, or event_new) but not yet
69 * released (via event_free or event_debug_unassign). If you want to use
70 * debug mode, and you find yourself running out of memory, you will need
71 * to use event_debug_unassign to explicitly stop tracking events that
72 * are no longer considered set-up.
74 void event_enable_debug_mode(void);
77 * When debugging mode is enabled, informs Libevent that an event should no
78 * longer be considered as assigned. When debugging mode is not enabled, does
81 * This function must only be called on a non-added event.
83 void event_debug_unassign(struct event *);
86 Initialize the event API.
88 Use event_base_new() to initialize a new event base.
90 @see event_base_set(), event_base_free(),
91 event_base_new_with_config()
93 struct event_base *event_base_new(void);
96 Reinitialized the event base after a fork
98 Some event mechanisms do not survive across fork. The event base needs
99 to be reinitialized with the event_reinit() function.
101 @param base the event base that needs to be re-initialized
102 @return 0 if successful, or -1 if some events could not be re-added.
103 @see event_base_new(), event_init()
105 int event_reinit(struct event_base *base);
108 Threadsafe event dispatching loop.
110 This loop will run the event base until either there are no more added
111 events, or until something calls event_base_loopbreak() or
112 evenet_base_loopexit().
114 @param eb the event_base structure returned by event_init()
115 @see event_init(), event_dispatch()
117 int event_base_dispatch(struct event_base *);
120 Get the kernel event notification mechanism used by Libevent.
122 @param eb the event_base structure returned by event_base_new()
123 @return a string identifying the kernel event mechanism (kqueue, epoll, etc.)
125 const char *event_base_get_method(const struct event_base *);
128 Gets all event notification mechanisms supported by Libevent.
130 This functions returns the event mechanism in order preferred by
131 Libevent. Note that this list will include all backends that
132 Libevent has compiled-in support for, and will not necessarily check
133 your OS to see whether it has the required resources.
135 @return an array with pointers to the names of support methods.
136 The end of the array is indicated by a NULL pointer. If an
137 error is encountered NULL is returned.
139 const char **event_get_supported_methods(void);
142 Allocates a new event configuration object.
144 The event configuration object can be used to change the behavior of
147 @return an event_config object that can be used to store configuration or
148 NULL when an error is encountered.
151 struct event_config *event_config_new(void);
154 Deallocates all memory associated with an event configuration object
156 @param cfg the event configuration object to be freed.
158 void event_config_free(struct event_config *cfg);
161 Enters an event method that should be avoided into the configuration.
163 This can be used to avoid event mechanisms that do not support certain
164 file descriptor types. An application can make use of multiple event
165 bases to accommodate incompatible file descriptor types.
167 @param cfg the event configuration object
168 @param method the event method to avoid
169 @return 0 on success, -1 on failure.
171 int event_config_avoid_method(struct event_config *cfg, const char *method);
173 enum event_method_feature {
174 /* Require an event method that allows edge-triggered events with EV_ET. */
175 EV_FEATURE_ET = 0x01,
176 /* Require an event method where having one event triggered among
177 * many is [approximately] an O(1) operation. This excludes (for
178 * example) select and poll, which are approximately O(N) for N
179 * equal to the total number of possible events. */
180 EV_FEATURE_O1 = 0x02,
181 /* Require an event method that allows file descriptors as well as
183 EV_FEATURE_FDS = 0x04
186 enum event_base_config_flag {
187 /** Do not allocate a lock for the event base, even if we have
189 EVENT_BASE_FLAG_NOLOCK = 0x01,
190 /** Do not check the EVENT_* environment variables when configuring
192 EVENT_BASE_FLAG_IGNORE_ENV = 0x02,
193 /** Windows only: enable the IOCP dispatcher at startup */
194 EVENT_BASE_FLAG_STARTUP_IOCP = 0x04,
195 /** Instead of checking the current time every time the event loop is
196 ready to run timeout callbacks, check after each timeout callback.
198 EVENT_BASE_FLAG_NO_CACHE_TIME = 0x08,
200 /** If we are using the epoll backend, this flag says that it is
201 safe to use Libevent's internal change-list code to batch up
202 adds and deletes in order to try to do as few syscalls as
203 possible. Setting this flag can make your code run faster, but
204 it may trigger a Linux bug: it is not safe to use this flag
205 if you have any fds cloned by dup() or its variants. Doing so
206 will produce strange and hard-to-diagnose bugs.
208 This flag can also be activated by settnig the
209 EVENT_EPOLL_USE_CHANGELIST environment variable.
211 This flag has no effect if you wind up using a backend other than
214 EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST = 0x10
218 Return a bitmask of the features implemented by an event base.
220 int event_base_get_features(const struct event_base *base);
223 Enters a required event method feature that the application demands.
225 Note that not every feature or combination of features is supported
226 on every platform. Code that requests features should be prepared
227 to handle the case where event_base_new_with_config() returns NULL, as in:
229 event_config_require_features(cfg, EV_FEATURE_ET);
230 base = event_base_new_with_config(cfg);
232 // We can't get edge-triggered behavior here.
233 event_config_require_features(cfg, 0);
234 base = event_base_new_with_config(cfg);
238 @param cfg the event configuration object
239 @param feature a bitfield of one or more event_method_feature values.
240 Replaces values from previous calls to this function.
241 @return 0 on success, -1 on failure.
243 int event_config_require_features(struct event_config *cfg, int feature);
245 /** Sets one or more flags to configure what parts of the eventual event_base
246 * will be initialized, and how they'll work. */
247 int event_config_set_flag(struct event_config *cfg, int flag);
250 * Records a hint for the number of CPUs in the system. This is used for
251 * tuning thread pools, etc, for optimal performance. In Libevent 2.0,
252 * it is only on Windows, and only when IOCP is in use.
254 * @param cfg the event configuration object
255 * @param cpus the number of cpus
256 * @return 0 on success, -1 on failure.
258 int event_config_set_num_cpus_hint(struct event_config *cfg, int cpus);
261 Initialize the event API.
263 Use event_base_new_with_config() to initialize a new event base, taking
264 the specified configuration under consideration. The configuration object
265 can currently be used to avoid certain event notification mechanisms.
267 @param cfg the event configuration object
268 @return an initialized event_base that can be used to registering events,
269 or NULL if no event base can be created with the requested event_config.
270 @see event_base_new(), event_base_free(), event_init(), event_assign()
272 struct event_base *event_base_new_with_config(const struct event_config *);
275 Deallocate all memory associated with an event_base, and free the base.
277 Note that this function will not close any fds or free any memory passed
278 to event_set as the argument to callback.
280 @param eb an event_base to be freed
282 void event_base_free(struct event_base *);
284 #define _EVENT_LOG_DEBUG 0
285 #define _EVENT_LOG_MSG 1
286 #define _EVENT_LOG_WARN 2
287 #define _EVENT_LOG_ERR 3
290 A callback function used to intercept Libevent's log messages.
292 typedef void (*event_log_cb)(int severity, const char *msg);
294 Redirect Libevent's log messages.
296 @param cb a function taking two arguments: an integer severity between
297 _EVENT_LOG_DEBUG and _EVENT_LOG_ERR, and a string. If cb is NULL,
298 then the default log is used.
300 NOTE: The function you provide *must not* call any other libevent
301 functionality. Doing so can produce undefined behavior.
303 void event_set_log_callback(event_log_cb cb);
306 Override Libevent's behavior in the event of a fatal internal error.
308 By default, Libevent will call exit(1) if a programming error makes it
309 impossible to continue correct operation. This function allows you to supply
310 another callback instead. Note that if the function is ever invoked,
311 something is wrong with your program, or with Libevent: any subsequent calls
312 to Libevent may result in undefined behavior.
314 Libevent will (almost) always log an _EVENT_LOG_ERR message before calling
315 this function; look at the last log message to see why Libevent has died.
317 typedef void (*event_fatal_cb)(int err);
318 void event_set_fatal_callback(event_fatal_cb cb);
321 Associate a different event base with an event.
323 @param eb the event base
326 int event_base_set(struct event_base *, struct event *);
329 event_base_loop() flags
332 /** Block until we have an active event, then exit once all active events
333 * have had their callbacks run. */
334 #define EVLOOP_ONCE 0x01
335 /** Do not block: see which events are ready now, run the callbacks
336 * of the highest-priority ones, then exit. */
337 #define EVLOOP_NONBLOCK 0x02
341 Handle events (threadsafe version).
343 This is a more flexible version of event_base_dispatch().
345 By default, this loop will run the event base until either there are no more
346 added events, or until something calls event_base_loopbreak() or
347 evenet_base_loopexit(). You can override this behavior with the 'flags'
350 @param eb the event_base structure returned by event_init()
351 @param flags any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK
352 @return 0 if successful, -1 if an error occurred, or 1 if no events were
354 @see event_loopexit(), event_base_loop()
356 int event_base_loop(struct event_base *, int);
359 Exit the event loop after the specified time (threadsafe variant).
361 The next event_base_loop() iteration after the given timer expires will
362 complete normally (handling all queued events) then exit without
363 blocking for events again.
365 Subsequent invocations of event_base_loop() will proceed normally.
367 @param eb the event_base structure returned by event_init()
368 @param tv the amount of time after which the loop should terminate.
369 @return 0 if successful, or -1 if an error occurred
370 @see event_loopexit()
372 int event_base_loopexit(struct event_base *, const struct timeval *);
375 Abort the active event_base_loop() immediately.
377 event_base_loop() will abort the loop after the next event is completed;
378 event_base_loopbreak() is typically invoked from this event's callback.
379 This behavior is analogous to the "break;" statement.
381 Subsequent invocations of event_loop() will proceed normally.
383 @param eb the event_base structure returned by event_init()
384 @return 0 if successful, or -1 if an error occurred
385 @see event_base_loopexit
387 int event_base_loopbreak(struct event_base *);
390 Checks if the event loop was told to exit by event_loopexit().
392 This function will return true for an event_base at every point after
393 event_loopexit() is called, until the event loop is next entered.
395 @param eb the event_base structure returned by event_init()
396 @return true if event_base_loopexit() was called on this event base,
398 @see event_base_loopexit
399 @see event_base_got_break
401 int event_base_got_exit(struct event_base *);
404 Checks if the event loop was told to abort immediately by event_loopbreak().
406 This function will return true for an event_base at every point after
407 event_loopbreak() is called, until the event loop is next entered.
409 @param eb the event_base structure returned by event_init()
410 @return true if event_base_loopbreak() was called on this event base,
412 @see event_base_loopbreak
413 @see event_base_got_exit
415 int event_base_got_break(struct event_base *);
417 /* Flags to pass to event_set(), event_new(), event_assign(),
418 * event_pending(), and anything else with an argument of the form
420 #define EV_TIMEOUT 0x01
422 #define EV_WRITE 0x04
423 #define EV_SIGNAL 0x08
424 /** Persistent event: won't get removed automatically when activated. */
425 #define EV_PERSIST 0x10
426 /** Select edge-triggered behavior, if supported by the backend. */
430 Define a timer event.
432 @param ev event struct to be modified
433 @param b an event_base
434 @param cb callback function
435 @param arg argument that will be passed to the callback function
437 #define evtimer_assign(ev, b, cb, arg) \
438 event_assign((ev), (b), -1, 0, (cb), (arg))
439 #define evtimer_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg))
444 @param ev the event struct
445 @param tv timeval struct
447 #define evtimer_add(ev, tv) event_add((ev), (tv))
450 * Delete a timer event.
452 * @param ev the event struct to be disabled
454 #define evtimer_del(ev) event_del(ev)
455 #define evtimer_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv))
456 #define evtimer_initialized(ev) event_initialized(ev)
458 #define evsignal_add(ev, tv) event_add((ev), (tv))
459 #define evsignal_assign(ev, b, x, cb, arg) \
460 event_assign((ev), (b), (x), EV_SIGNAL|EV_PERSIST, cb, (arg))
461 #define evsignal_new(b, x, cb, arg) \
462 event_new((b), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
463 #define evsignal_del(ev) event_del(ev)
464 #define evsignal_pending(ev, tv) event_pending((ev), EV_SIGNAL, (tv))
465 #define evsignal_initialized(ev) event_initialized(ev)
467 typedef void (*event_callback_fn)(evutil_socket_t, short, void *);
470 Prepare an event structure to be added.
472 The function event_assign() prepares the event structure ev to be used in
473 future calls to event_add() and event_del(). The event will be prepared to
474 call the function specified by the fn argument with an int argument
475 indicating the file descriptor, a short argument indicating the type of
476 event, and a void * argument given in the arg argument. The fd indicates
477 the file descriptor that should be monitored for events. The events can be
478 either EV_READ, EV_WRITE, or both. Indicating that an application can read
479 or write from the file descriptor respectively without blocking.
481 The function fn will be called with the file descriptor that triggered the
482 event and the type of event which will be either EV_TIMEOUT, EV_SIGNAL,
483 EV_READ, or EV_WRITE. The additional flag EV_PERSIST makes an event_add()
484 persistent until event_del() has been called.
486 Note that using event_assign() request that you have already allocated the
487 event struct. Doing so will often require your code to depend on the size
488 of the structure, and will create possible incompatibility with future
489 versions of Libevent. If this seems like a bad idea to you, use event_new()
490 and event_free() instead.
492 @param ev an event struct to be modified
493 @param base the event base to which ev should be attached.
494 @param fd the file descriptor to be monitored
495 @param event desired events to monitor; can be EV_READ and/or EV_WRITE
496 @param fn callback function to be invoked when the event occurs
497 @param arg an argument to be passed to the callback function
499 @return 0 if success, or -1 on invalid arguments.
501 @see event_add(), event_del(), event_once()
504 int event_assign(struct event *, struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
507 Create and allocate a new event structure, ready to be added.
509 Arguments are as for event_assign; returns a newly allocated struct event *
510 that must later be deallocated with event_free().
513 struct event *event_new(struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
516 Deallocate a struct event * returned by event_new().
518 void event_free(struct event *);
521 Schedule a one-time event
523 The function event_base_once() is similar to event_set(). However, it
524 schedules a callback to be called exactly once and does not require the
525 caller to prepare an event structure.
527 @param base an event_base returned by event_init()
528 @param fd a file descriptor to monitor
529 @param events event(s) to monitor; can be any of EV_TIMEOUT | EV_READ |
531 @param callback callback function to be invoked when the event occurs
532 @param arg an argument to be passed to the callback function
533 @param timeout the maximum amount of time to wait for the event, or NULL
535 @return 0 if successful, or -1 if an error occurred
538 int event_base_once(struct event_base *, evutil_socket_t, short, event_callback_fn, void *, const struct timeval *);
541 Add an event to the set of monitored events.
543 The function event_add() schedules the execution of the ev event when the
544 event specified in event_set() occurs or in at least the time specified in
545 the tv. If tv is NULL, no timeout occurs and the function will only be
546 called if a matching event occurs on the file descriptor. The event in the
547 ev argument must be already initialized by event_set() and may not be used
548 in calls to event_set() until it has timed out or been removed with
549 event_del(). If the event in the ev argument already has a scheduled
550 timeout, the old timeout will be replaced by the new one.
552 @param ev an event struct initialized via event_set()
553 @param timeout the maximum amount of time to wait for the event, or NULL
555 @return 0 if successful, or -1 if an error occurred
556 @see event_del(), event_set()
558 int event_add(struct event *, const struct timeval *);
561 Remove an event from the set of monitored events.
563 The function event_del() will cancel the event in the argument ev. If the
564 event has already executed or has never been added the call will have no
567 @param ev an event struct to be removed from the working set
568 @return 0 if successful, or -1 if an error occurred
571 int event_del(struct event *);
575 Make an event active.
577 @param ev an event to make active.
578 @param res a set of flags to pass to the event's callback.
581 void event_active(struct event *, int, short);
585 Checks if a specific event is pending or scheduled.
587 @param ev an event struct previously passed to event_add()
588 @param what the requested event type; any of EV_TIMEOUT|EV_READ|
590 @param tv if this field is not NULL, and the event has a timeout,
591 this field is set to hold the time at which the timeout will
594 @return true if the event is pending on any of the events in 'what', (that
595 is to say, it has been added), or 0 if the event is not added.
598 int event_pending(const struct event *, short, struct timeval *);
602 Test if an event structure might be initialized.
604 The event_initialized() function can be used to check if an event has been
607 Warning: This function is only useful for distinguishing a a zeroed-out
608 piece of memory from an initialized event, it can easily be confused by
609 uninitialized memory. Thus, it should ONLY be used to distinguish an
610 initialized event from zero.
612 @param ev an event structure to be tested
613 @return 1 if the structure might be initialized, or 0 if it has not been
616 int event_initialized(const struct event *ev);
619 Get the signal number assigned to an event.
621 #define event_get_signal(ev) ((int)event_get_fd(ev))
624 Get the socket assigned to an event.
626 evutil_socket_t event_get_fd(const struct event *ev);
629 Get the event_base assigned to an event.
631 struct event_base *event_get_base(const struct event *ev);
634 Return the events (EV_READ, EV_WRITE, etc) assigned to an event.
636 short event_get_events(const struct event *ev);
639 Return the callback assigned to an event.
641 event_callback_fn event_get_callback(const struct event *ev);
644 Return the callback argument assigned to an event.
646 void *event_get_callback_arg(const struct event *ev);
649 Extract _all_ of arguments given to construct a given event. The
650 event_base is copied into *base_out, the fd is copied into *fd_out, and so
653 If any of the "_out" arguments is NULL, it will be ignored.
655 void event_get_assignment(const struct event *event,
656 struct event_base **base_out, evutil_socket_t *fd_out, short *events_out,
657 event_callback_fn *callback_out, void **arg_out);
660 Return the size of struct event that the Libevent library was compiled
663 This will be NO GREATER than sizeof(struct event) if you're running with
664 the same version of Libevent that your application was built with, but
667 Note that it might be SMALLER than sizeof(struct event) if some future
668 version of Libevent adds extra padding to the end of struct event.
669 We might do this to help ensure ABI-compatibility between different
670 versions of Libevent.
672 size_t event_get_struct_event_size(void);
675 Get the Libevent version.
677 Note that this will give you the version of the library that you're
678 currently linked against, not the version of the headers that you've
681 @return a string containing the version number of Libevent
683 const char *event_get_version(void);
686 Return a numeric representation of Libevent's version.
688 Note that this will give you the version of the library that you're
689 currently linked against, not the version of the headers you've used to
692 The format uses one byte each for the major, minor, and patchlevel parts of
693 the version number. The low-order byte is unused. For example, version
694 2.0.1-alpha has a numeric representation of 0x02000100
696 ev_uint32_t event_get_version_number(void);
698 /** As event_get_version, but gives the version of Libevent's headers. */
699 #define LIBEVENT_VERSION _EVENT_VERSION
700 /** As event_get_version_number, but gives the version number of Libevent's
702 #define LIBEVENT_VERSION_NUMBER _EVENT_NUMERIC_VERSION
704 #define EVENT_MAX_PRIORITIES 256
706 Set the number of different event priorities (threadsafe variant).
708 See the description of event_priority_init() for more information.
710 @param eb the event_base structure returned by event_init()
711 @param npriorities the maximum number of priorities
712 @return 0 if successful, or -1 if an error occurred
713 @see event_priority_init(), event_priority_set()
715 int event_base_priority_init(struct event_base *, int);
719 Assign a priority to an event.
721 @param ev an event struct
722 @param priority the new priority to be assigned
723 @return 0 if successful, or -1 if an error occurred
724 @see event_priority_init()
726 int event_priority_set(struct event *, int);
729 Prepare Libevent to use a large number of timeouts with the same duration.
731 Libevent's default scheduling algorithm is optimized for having a large
732 number of timeouts with their durations more or less randomly distributed.
733 If you have a large number of timeouts that all have the same duration (for
734 example, if you have a large number of connections that all have a
735 10-second timeout), then you can improve Libevent's performance by telling
738 To do this, call this function with the common duration. It will return a
739 pointer to a different, opaque timeout value. (Don't depend on its actual
740 contents!) When you use this timeout value in event_add(), Libevent will
741 schedule the event more efficiently.
743 (This optimization probably will not be worthwhile until you have thousands
744 or tens of thousands of events with the same timeout.)
746 const struct timeval *event_base_init_common_timeout(struct event_base *base,
747 const struct timeval *duration);
749 #ifndef _EVENT_DISABLE_MM_REPLACEMENT
751 Override the functions that Libevent uses for memory management.
753 Usually, Libevent uses the standard libc functions malloc, realloc, and
754 free to allocate memory. Passing replacements for those functions to
755 event_set_mem_functions() overrides this behavior. To restore the default
756 behavior, pass NULLs as the arguments to this function.
758 Note that all memory returned from Libevent will be allocated by the
759 replacement functions rather than by malloc() and realloc(). Thus, if you
760 have replaced those functions, it will not be appropriate to free() memory
761 that you get from Libevent. Instead, you must use the free_fn replacement
764 @param malloc_fn A replacement for malloc.
765 @param realloc_fn A replacement for realloc
766 @param free_fn A replacement for free.
768 void event_set_mem_functions(
769 void *(*malloc_fn)(size_t sz),
770 void *(*realloc_fn)(void *ptr, size_t sz),
771 void (*free_fn)(void *ptr));
772 #define EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
775 void event_base_dump_events(struct event_base *, FILE *);
777 /** Sets 'tv' to the current time (as returned by gettimeofday()),
778 looking at the cached value in 'base' if possible, and calling
779 gettimeofday() or clock_gettime() as appropriate if there is no
782 Generally, this value will only be cached while actually
783 processing event callbacks, and may be very inaccuate if your
784 callbacks take a long time to execute.
786 Returns 0 on success, negative on failure.
788 int event_base_gettimeofday_cached(struct event_base *base,
795 #endif /* _EVENT2_EVENT_H_ */