transmission: update from 2.13 to 2.22
[tomato.git] / release / src / router / libevent / include / event2 / event.h
blob4b05b32538cfb589a1d60b3a9c4f9eb25c263b04
1 /*
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
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.
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.
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
40 #include <event2/event-config.h>
41 #ifdef _EVENT_HAVE_SYS_TYPES_H
42 #include <sys/types.h>
43 #endif
44 #ifdef _EVENT_HAVE_SYS_TIME_H
45 #include <sys/time.h>
46 #endif
48 #include <stdio.h>
50 /* For int types. */
51 #include <event2/util.h>
53 struct event_base;
54 struct event;
55 struct event_config;
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
61 * created.
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);
76 /**
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
79 * nothing.
81 * This function must only be called on a non-added event.
83 void event_debug_unassign(struct event *);
85 /**
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);
95 /**
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 @param eb the event_base structure returned by event_init()
111 @see event_init(), event_dispatch()
113 int event_base_dispatch(struct event_base *);
116 Get the kernel event notification mechanism used by Libevent.
118 @param eb the event_base structure returned by event_base_new()
119 @return a string identifying the kernel event mechanism (kqueue, epoll, etc.)
121 const char *event_base_get_method(const struct event_base *);
124 Gets all event notification mechanisms supported by Libevent.
126 This functions returns the event mechanism in order preferred by
127 Libevent. Note that this list will include all backends that
128 Libevent has compiled-in support for, and will not necessarily check
129 your OS to see whether it has the required resources.
131 @return an array with pointers to the names of support methods.
132 The end of the array is indicated by a NULL pointer. If an
133 error is encountered NULL is returned.
135 const char **event_get_supported_methods(void);
138 Allocates a new event configuration object.
140 The event configuration object can be used to change the behavior of
141 an event base.
143 @return an event_config object that can be used to store configuration or
144 NULL when an error is encountered.
147 struct event_config *event_config_new(void);
150 Deallocates all memory associated with an event configuration object
152 @param cfg the event configuration object to be freed.
154 void event_config_free(struct event_config *cfg);
157 Enters an event method that should be avoided into the configuration.
159 This can be used to avoid event mechanisms that do not support certain
160 file descriptor types. An application can make use of multiple event
161 bases to accommodate incompatible file descriptor types.
163 @param cfg the event configuration object
164 @param method the event method to avoid
165 @return 0 on success, -1 on failure.
167 int event_config_avoid_method(struct event_config *cfg, const char *method);
169 enum event_method_feature {
170 /* Require an event method that allows edge-triggered events with EV_ET. */
171 EV_FEATURE_ET = 0x01,
172 /* Require an event method where having one event triggered among
173 * many is [approximately] an O(1) operation. This excludes (for
174 * example) select and poll, which are approximately O(N) for N
175 * equal to the total number of possible events. */
176 EV_FEATURE_O1 = 0x02,
177 /* Require an event method that allows file descriptors as well as
178 * sockets. */
179 EV_FEATURE_FDS = 0x04
182 enum event_base_config_flag {
183 /** Do not allocate a lock for the event base, even if we have
184 locking set up. */
185 EVENT_BASE_FLAG_NOLOCK = 0x01,
186 /** Do not check the EVENT_* environment variables when configuring
187 an event_base */
188 EVENT_BASE_FLAG_IGNORE_ENV = 0x02,
189 /** Windows only: enable the IOCP dispatcher at startup */
190 EVENT_BASE_FLAG_STARTUP_IOCP = 0x04,
191 /** Instead of checking the current time every time the event loop is
192 ready to run timeout callbacks, check after each timeout callback.
194 EVENT_BASE_FLAG_NO_CACHE_TIME = 0x08,
196 /** If we are using the epoll backend, this flag says that it is
197 safe to use Libevent's internal change-list code to batch up
198 adds and deletes in order to try to do as few syscalls as
199 possible. Setting this flag can make your code run faster, but
200 it may trigger a Linux bug: it is not safe to use this flag
201 if you have any fds cloned by dup() or its variants. Doing so
202 will produce strange and hard-to-diagnose bugs.
204 This flag can also be activated by settnig the
205 EVENT_EPOLL_USE_CHANGELIST environment variable.
207 This flag has no effect if you wind up using a backend other than
208 epoll.
210 EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST = 0x10
214 Return a bitmask of the features implemented by an event base.
216 int event_base_get_features(const struct event_base *base);
219 Enters a required event method feature that the application demands.
221 Note that not every feature or combination of features is supported
222 on every platform. Code that requests features should be prepared
223 to handle the case where event_base_new_with_config() returns NULL, as in:
224 <pre>
225 event_config_require_features(cfg, EV_FEATURE_ET);
226 base = event_base_new_with_config(cfg);
227 if (base == NULL) {
228 // We can't get edge-triggered behavior here.
229 event_config_require_features(cfg, 0);
230 base = event_base_new_with_config(cfg);
232 </pre>
234 @param cfg the event configuration object
235 @param feature a bitfield of one or more event_method_feature values.
236 Replaces values from previous calls to this function.
237 @return 0 on success, -1 on failure.
239 int event_config_require_features(struct event_config *cfg, int feature);
241 /** Sets one or more flags to configure what parts of the eventual event_base
242 * will be initialized, and how they'll work. */
243 int event_config_set_flag(struct event_config *cfg, int flag);
246 * Records a hint for the number of CPUs in the system. This is used for
247 * tuning thread pools, etc, for optimal performance. In Libevent 2.0,
248 * it is only on Windows, and only when IOCP is in use.
250 * @param cfg the event configuration object
251 * @param cpus the number of cpus
252 * @return 0 on success, -1 on failure.
254 int event_config_set_num_cpus_hint(struct event_config *cfg, int cpus);
257 Initialize the event API.
259 Use event_base_new_with_config() to initialize a new event base, taking
260 the specified configuration under consideration. The configuration object
261 can currently be used to avoid certain event notification mechanisms.
263 @param cfg the event configuration object
264 @return an initialized event_base that can be used to registering events,
265 or NULL if no event base can be created with the requested event_config.
266 @see event_base_new(), event_base_free(), event_init(), event_assign()
268 struct event_base *event_base_new_with_config(const struct event_config *);
271 Deallocate all memory associated with an event_base, and free the base.
273 Note that this function will not close any fds or free any memory passed
274 to event_set as the argument to callback.
276 @param eb an event_base to be freed
278 void event_base_free(struct event_base *);
280 #define _EVENT_LOG_DEBUG 0
281 #define _EVENT_LOG_MSG 1
282 #define _EVENT_LOG_WARN 2
283 #define _EVENT_LOG_ERR 3
286 A callback function used to intercept Libevent's log messages.
288 typedef void (*event_log_cb)(int severity, const char *msg);
290 Redirect Libevent's log messages.
292 @param cb a function taking two arguments: an integer severity between
293 _EVENT_LOG_DEBUG and _EVENT_LOG_ERR, and a string. If cb is NULL,
294 then the default log is used.
296 NOTE: The function you provide *must not* call any other libevent
297 functionality. Doing so can produce undefined behavior.
299 void event_set_log_callback(event_log_cb cb);
302 Override Libevent's behavior in the event of a fatal internal error.
304 By default, Libevent will call exit(1) if a programming error makes it
305 impossible to continue correct operation. This function allows you to supply
306 another callback instead. Note that if the function is ever invoked,
307 something is wrong with your program, or with Libevent: any subsequent calls
308 to Libevent may result in undefined behavior.
310 Libevent will (almost) always log an _EVENT_LOG_ERR message before calling
311 this function; look at the last log message to see why Libevent has died.
313 typedef void (*event_fatal_cb)(int err);
314 void event_set_fatal_callback(event_fatal_cb cb);
317 Associate a different event base with an event.
319 @param eb the event base
320 @param ev the event
322 int event_base_set(struct event_base *, struct event *);
325 event_loop() flags
327 /*@{*/
328 /** Block until we have an active event, then exit once all active events
329 * have had their callbacks run. */
330 #define EVLOOP_ONCE 0x01
331 /** Do not block: see which events are ready now, run the callbacks
332 * highest-priority ones, then exit. */
333 #define EVLOOP_NONBLOCK 0x02
334 /*@}*/
337 Handle events (threadsafe version).
339 This is a more flexible version of event_base_dispatch().
341 @param eb the event_base structure returned by event_init()
342 @param flags any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK
343 @return 0 if successful, -1 if an error occurred, or 1 if no events were
344 registered.
345 @see event_loopexit(), event_base_loop()
347 int event_base_loop(struct event_base *, int);
350 Exit the event loop after the specified time (threadsafe variant).
352 The next event_base_loop() iteration after the given timer expires will
353 complete normally (handling all queued events) then exit without
354 blocking for events again.
356 Subsequent invocations of event_base_loop() will proceed normally.
358 @param eb the event_base structure returned by event_init()
359 @param tv the amount of time after which the loop should terminate.
360 @return 0 if successful, or -1 if an error occurred
361 @see event_loopexit()
363 int event_base_loopexit(struct event_base *, const struct timeval *);
366 Abort the active event_base_loop() immediately.
368 event_base_loop() will abort the loop after the next event is completed;
369 event_base_loopbreak() is typically invoked from this event's callback.
370 This behavior is analogous to the "break;" statement.
372 Subsequent invocations of event_loop() will proceed normally.
374 @param eb the event_base structure returned by event_init()
375 @return 0 if successful, or -1 if an error occurred
376 @see event_base_loopexit
378 int event_base_loopbreak(struct event_base *);
381 Checks if the event loop was told to exit by event_loopexit().
383 This function will return true for an event_base at every point after
384 event_loopexit() is called, until the event loop is next entered.
386 @param eb the event_base structure returned by event_init()
387 @return true if event_base_loopexit() was called on this event base,
388 or 0 otherwise
389 @see event_base_loopexit
390 @see event_base_got_break
392 int event_base_got_exit(struct event_base *);
395 Checks if the event loop was told to abort immediately by event_loopbreak().
397 This function will return true for an event_base at every point after
398 event_loopbreak() is called, until the event loop is next entered.
400 @param eb the event_base structure returned by event_init()
401 @return true if event_base_loopbreak() was called on this event base,
402 or 0 otherwise
403 @see event_base_loopbreak
404 @see event_base_got_exit
406 int event_base_got_break(struct event_base *);
408 /* Flags to pass to event_set(), event_new(), event_assign(),
409 * event_pending(), and anything else with an argument of the form
410 * "short events" */
411 #define EV_TIMEOUT 0x01
412 #define EV_READ 0x02
413 #define EV_WRITE 0x04
414 #define EV_SIGNAL 0x08
415 /** Persistent event: won't get removed automatically when activated. */
416 #define EV_PERSIST 0x10
417 /** Select edge-triggered behavior, if supported by the backend. */
418 #define EV_ET 0x20
421 Define a timer event.
423 @param ev event struct to be modified
424 @param b an event_base
425 @param cb callback function
426 @param arg argument that will be passed to the callback function
428 #define evtimer_assign(ev, b, cb, arg) \
429 event_assign((ev), (b), -1, 0, (cb), (arg))
430 #define evtimer_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg))
433 Add a timer event.
435 @param ev the event struct
436 @param tv timeval struct
438 #define evtimer_add(ev, tv) event_add((ev), (tv))
441 * Delete a timer event.
443 * @param ev the event struct to be disabled
445 #define evtimer_del(ev) event_del(ev)
446 #define evtimer_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv))
447 #define evtimer_initialized(ev) event_initialized(ev)
449 #define evsignal_add(ev, tv) event_add((ev), (tv))
450 #define evsignal_assign(ev, b, x, cb, arg) \
451 event_assign((ev), (b), (x), EV_SIGNAL|EV_PERSIST, cb, (arg))
452 #define evsignal_new(b, x, cb, arg) \
453 event_new((b), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
454 #define evsignal_del(ev) event_del(ev)
455 #define evsignal_pending(ev, tv) event_pending((ev), EV_SIGNAL, (tv))
456 #define evsignal_initialized(ev) event_initialized(ev)
458 typedef void (*event_callback_fn)(evutil_socket_t, short, void *);
461 Prepare an event structure to be added.
463 The function event_assign() prepares the event structure ev to be used in
464 future calls to event_add() and event_del(). The event will be prepared to
465 call the function specified by the fn argument with an int argument
466 indicating the file descriptor, a short argument indicating the type of
467 event, and a void * argument given in the arg argument. The fd indicates
468 the file descriptor that should be monitored for events. The events can be
469 either EV_READ, EV_WRITE, or both. Indicating that an application can read
470 or write from the file descriptor respectively without blocking.
472 The function fn will be called with the file descriptor that triggered the
473 event and the type of event which will be either EV_TIMEOUT, EV_SIGNAL,
474 EV_READ, or EV_WRITE. The additional flag EV_PERSIST makes an event_add()
475 persistent until event_del() has been called.
477 Note that using event_assign() request that you have already allocated the
478 event struct. Doing so will often require your code to depend on the size
479 of the structure, and will create possible incompatibility with future
480 versions of Libevent. If this seems like a bad idea to you, use event_new()
481 and event_free() instead.
483 @param ev an event struct to be modified
484 @param base the event base to which ev should be attached.
485 @param fd the file descriptor to be monitored
486 @param event desired events to monitor; can be EV_READ and/or EV_WRITE
487 @param fn callback function to be invoked when the event occurs
488 @param arg an argument to be passed to the callback function
490 @return 0 if success, or -1 on invalid arguments.
492 @see event_add(), event_del(), event_once()
495 int event_assign(struct event *, struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
498 Create and allocate a new event structure, ready to be added.
500 Arguments are as for event_assign; returns a newly allocated struct event *
501 that must later be deallocated with event_free().
504 struct event *event_new(struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
507 Deallocate a struct event * returned by event_new().
509 void event_free(struct event *);
512 Schedule a one-time event
514 The function event_base_once() is similar to event_set(). However, it
515 schedules a callback to be called exactly once and does not require the
516 caller to prepare an event structure.
518 @param base an event_base returned by event_init()
519 @param fd a file descriptor to monitor
520 @param events event(s) to monitor; can be any of EV_TIMEOUT | EV_READ |
521 EV_WRITE
522 @param callback callback function to be invoked when the event occurs
523 @param arg an argument to be passed to the callback function
524 @param timeout the maximum amount of time to wait for the event, or NULL
525 to wait forever
526 @return 0 if successful, or -1 if an error occurred
527 @see event_once()
529 int event_base_once(struct event_base *, evutil_socket_t, short, event_callback_fn, void *, const struct timeval *);
532 Add an event to the set of monitored events.
534 The function event_add() schedules the execution of the ev event when the
535 event specified in event_set() occurs or in at least the time specified in
536 the tv. If tv is NULL, no timeout occurs and the function will only be
537 called if a matching event occurs on the file descriptor. The event in the
538 ev argument must be already initialized by event_set() and may not be used
539 in calls to event_set() until it has timed out or been removed with
540 event_del(). If the event in the ev argument already has a scheduled
541 timeout, the old timeout will be replaced by the new one.
543 @param ev an event struct initialized via event_set()
544 @param timeout the maximum amount of time to wait for the event, or NULL
545 to wait forever
546 @return 0 if successful, or -1 if an error occurred
547 @see event_del(), event_set()
549 int event_add(struct event *, const struct timeval *);
552 Remove an event from the set of monitored events.
554 The function event_del() will cancel the event in the argument ev. If the
555 event has already executed or has never been added the call will have no
556 effect.
558 @param ev an event struct to be removed from the working set
559 @return 0 if successful, or -1 if an error occurred
560 @see event_add()
562 int event_del(struct event *);
566 Make an event active.
568 @param ev an event to make active.
569 @param res a set of flags to pass to the event's callback.
570 @param ncalls
572 void event_active(struct event *, int, short);
576 Checks if a specific event is pending or scheduled.
578 @param ev an event struct previously passed to event_add()
579 @param what the requested event type; any of EV_TIMEOUT|EV_READ|
580 EV_WRITE|EV_SIGNAL
581 @param tv if this field is not NULL, and the event has a timeout,
582 this field is set to hold the time at which the timeout will
583 expire.
585 @return true if the event is pending on any of the events in 'what', (that
586 is to say, it has been added), or 0 if the event is not added.
589 int event_pending(const struct event *, short, struct timeval *);
593 Test if an event structure might be initialized.
595 The event_initialized() function can be used to check if an event has been
596 initialized.
598 Warning: This function is only useful for distinguishing a a zeroed-out
599 piece of memory from an initialized event, it can easily be confused by
600 uninitialized memory. Thus, it should ONLY be used to distinguish an
601 initialized event from zero.
603 @param ev an event structure to be tested
604 @return 1 if the structure might be initialized, or 0 if it has not been
605 initialized
607 int event_initialized(const struct event *ev);
610 Get the signal number assigned to an event.
612 #define event_get_signal(ev) ((int)event_get_fd(ev))
615 Get the socket assigned to an event.
617 evutil_socket_t event_get_fd(const struct event *ev);
620 Get the event_base assigned to an event.
622 struct event_base *event_get_base(const struct event *ev);
625 Return the events (EV_READ, EV_WRITE, etc) assigned to an event.
627 short event_get_events(const struct event *ev);
630 Return the callback assigned to an event.
632 event_callback_fn event_get_callback(const struct event *ev);
635 Return the callback argument assigned to an event.
637 void *event_get_callback_arg(const struct event *ev);
640 Extract _all_ of arguments given to construct a given event. The
641 event_base is copied into *base_out, the fd is copied into *fd_out, and so
644 If any of the "_out" arguments is NULL, it will be ignored.
646 void event_get_assignment(const struct event *event,
647 struct event_base **base_out, evutil_socket_t *fd_out, short *events_out,
648 event_callback_fn *callback_out, void **arg_out);
651 Return the size of struct event that the Libevent library was compiled
652 with.
654 This will be NO GREATER than sizeof(struct event) if you're running with
655 the same version of Libevent that your application was built with, but
656 otherwise might not.
658 Note that it might be SMALLER than sizeof(struct event) if some future
659 version of Libevent adds extra padding to the end of struct event.
660 We might do this to help ensure ABI-compatibility between different
661 versions of Libevent.
663 size_t event_get_struct_event_size(void);
666 Get the Libevent version.
668 Note that this will give you the version of the library that you're
669 currently linked against, not the version of the headers that you've
670 compiled against.
672 @return a string containing the version number of Libevent
674 const char *event_get_version(void);
677 Return a numeric representation of Libevent's version.
679 Note that this will give you the version of the library that you're
680 currently linked against, not the version of the headers you've used to
681 compile.
683 The format uses one byte each for the major, minor, and patchlevel parts of
684 the version number. The low-order byte is unused. For example, version
685 2.0.1-alpha has a numeric representation of 0x02000100
687 ev_uint32_t event_get_version_number(void);
689 /** As event_get_version, but gives the version of Libevent's headers. */
690 #define LIBEVENT_VERSION _EVENT_VERSION
691 /** As event_get_version_number, but gives the version number of Libevent's
692 * headers. */
693 #define LIBEVENT_VERSION_NUMBER _EVENT_NUMERIC_VERSION
695 #define EVENT_MAX_PRIORITIES 256
697 Set the number of different event priorities (threadsafe variant).
699 See the description of event_priority_init() for more information.
701 @param eb the event_base structure returned by event_init()
702 @param npriorities the maximum number of priorities
703 @return 0 if successful, or -1 if an error occurred
704 @see event_priority_init(), event_priority_set()
706 int event_base_priority_init(struct event_base *, int);
710 Assign a priority to an event.
712 @param ev an event struct
713 @param priority the new priority to be assigned
714 @return 0 if successful, or -1 if an error occurred
715 @see event_priority_init()
717 int event_priority_set(struct event *, int);
720 Prepare Libevent to use a large number of timeouts with the same duration.
722 Libevent's default scheduling algorithm is optimized for having a large
723 number of timeouts with their durations more or less randomly distributed.
724 If you have a large number of timeouts that all have the same duration (for
725 example, if you have a large number of connections that all have a
726 10-second timeout), then you can improve Libevent's performance by telling
727 Libevent about it.
729 To do this, call this function with the common duration. It will return a
730 pointer to a different, opaque timeout value. (Don't depend on its actual
731 contents!) When you use this timeout value in event_add(), Libevent will
732 schedule the event more efficiently.
734 (This optimization probably will not be worthwhile until you have thousands
735 or tens of thousands of events with the same timeout.)
737 const struct timeval *event_base_init_common_timeout(struct event_base *base,
738 const struct timeval *duration);
740 #ifndef _EVENT_DISABLE_MM_REPLACEMENT
742 Override the functions that Libevent uses for memory management.
744 Usually, Libevent uses the standard libc functions malloc, realloc, and
745 free to allocate memory. Passing replacements for those functions to
746 event_set_mem_functions() overrides this behavior. To restore the default
747 behavior, pass NULLs as the arguments to this function.
749 Note that all memory returned from Libevent will be allocated by the
750 replacement functions rather than by malloc() and realloc(). Thus, if you
751 have replaced those functions, it may not be appropriate to free() memory
752 that you get from Libevent.
754 @param malloc_fn A replacement for malloc.
755 @param realloc_fn A replacement for realloc
756 @param free_fn A replacement for free.
758 void event_set_mem_functions(
759 void *(*malloc_fn)(size_t sz),
760 void *(*realloc_fn)(void *ptr, size_t sz),
761 void (*free_fn)(void *ptr));
762 #define EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
763 #endif
765 void event_base_dump_events(struct event_base *, FILE *);
767 /** Sets 'tv' to the current time (as returned by gettimeofday()),
768 looking at the cached value in 'base' if possible, and calling
769 gettimeofday() or clock_gettime() as appropriate if there is no
770 cached time.
772 Generally, this value will only be cached while actually
773 processing event callbacks, and may be very inaccuate if your
774 callbacks take a long time to execute.
776 Returns 0 on success, negative on failure.
778 int event_base_gettimeofday_cached(struct event_base *base,
779 struct timeval *tv);
781 #ifdef __cplusplus
783 #endif
785 #endif /* _EVENT2_EVENT_H_ */