]> arthur.barton.de Git - netatalk.git/blob - libevent/include/event2/event.h
Merge master
[netatalk.git] / libevent / include / event2 / event.h
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 /** @file event2/event.h
31
32   Core functions for waiting for and receiving events, and using event bases.
33
34 */
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
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
47
48 #include <stdio.h>
49
50 /* For int types. */
51 #include <event2/util.h>
52
53 struct event_base;
54 struct event;
55 struct event_config;
56
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.
62  *
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
66  *
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.
73  */
74 void event_enable_debug_mode(void);
75
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.
80  *
81  * This function must only be called on a non-added event.
82  */
83 void event_debug_unassign(struct event *);
84
85 /**
86   Initialize the event API.
87
88   Use event_base_new() to initialize a new event base.
89
90   @see event_base_set(), event_base_free(),
91     event_base_new_with_config()
92  */
93 struct event_base *event_base_new(void);
94
95 /**
96   Reinitialized the event base after a fork
97
98   Some event mechanisms do not survive across fork.   The event base needs
99   to be reinitialized with the event_reinit() function.
100
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()
104 */
105 int event_reinit(struct event_base *base);
106
107 /**
108   Threadsafe event dispatching loop.
109
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().
113
114   @param eb the event_base structure returned by event_init()
115   @see event_init(), event_dispatch()
116  */
117 int event_base_dispatch(struct event_base *);
118
119 /**
120  Get the kernel event notification mechanism used by Libevent.
121
122  @param eb the event_base structure returned by event_base_new()
123  @return a string identifying the kernel event mechanism (kqueue, epoll, etc.)
124  */
125 const char *event_base_get_method(const struct event_base *);
126
127 /**
128    Gets all event notification mechanisms supported by Libevent.
129
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.
134
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.
138 */
139 const char **event_get_supported_methods(void);
140
141 /**
142    Allocates a new event configuration object.
143
144    The event configuration object can be used to change the behavior of
145    an event base.
146
147    @return an event_config object that can be used to store configuration or
148      NULL when an error is encountered.
149 */
150
151 struct event_config *event_config_new(void);
152
153 /**
154    Deallocates all memory associated with an event configuration object
155
156    @param cfg the event configuration object to be freed.
157 */
158 void event_config_free(struct event_config *cfg);
159
160 /**
161    Enters an event method that should be avoided into the configuration.
162
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.
166
167    @param cfg the event configuration object
168    @param method the event method to avoid
169    @return 0 on success, -1 on failure.
170 */
171 int event_config_avoid_method(struct event_config *cfg, const char *method);
172
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
182      * sockets. */
183     EV_FEATURE_FDS = 0x04
184 };
185
186 enum event_base_config_flag {
187         /** Do not allocate a lock for the event base, even if we have
188             locking set up. */
189         EVENT_BASE_FLAG_NOLOCK = 0x01,
190         /** Do not check the EVENT_* environment variables when configuring
191             an event_base  */
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.
197          */
198         EVENT_BASE_FLAG_NO_CACHE_TIME = 0x08,
199
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.
207
208             This flag can also be activated by settnig the
209             EVENT_EPOLL_USE_CHANGELIST environment variable.
210
211             This flag has no effect if you wind up using a backend other than
212             epoll.
213          */
214         EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST = 0x10
215 };
216
217 /**
218  Return a bitmask of the features implemented by an event base.
219  */
220 int event_base_get_features(const struct event_base *base);
221
222 /**
223    Enters a required event method feature that the application demands.
224
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:
228    <pre>
229      event_config_require_features(cfg, EV_FEATURE_ET);
230      base = event_base_new_with_config(cfg);
231      if (base == NULL) {
232        // We can't get edge-triggered behavior here.
233        event_config_require_features(cfg, 0);
234        base = event_base_new_with_config(cfg);
235      }
236    </pre>
237
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.
242 */
243 int event_config_require_features(struct event_config *cfg, int feature);
244
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);
248
249 /**
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.
253  *
254  * @param cfg the event configuration object
255  * @param cpus the number of cpus
256  * @return 0 on success, -1 on failure.
257  */
258 int event_config_set_num_cpus_hint(struct event_config *cfg, int cpus);
259
260 /**
261   Initialize the event API.
262
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.
266
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()
271 */
272 struct event_base *event_base_new_with_config(const struct event_config *);
273
274 /**
275   Deallocate all memory associated with an event_base, and free the base.
276
277   Note that this function will not close any fds or free any memory passed
278   to event_set as the argument to callback.
279
280   @param eb an event_base to be freed
281  */
282 void event_base_free(struct event_base *);
283
284 #define _EVENT_LOG_DEBUG 0
285 #define _EVENT_LOG_MSG   1
286 #define _EVENT_LOG_WARN  2
287 #define _EVENT_LOG_ERR   3
288
289 /*
290   A callback function used to intercept Libevent's log messages.
291  */
292 typedef void (*event_log_cb)(int severity, const char *msg);
293 /**
294   Redirect Libevent's log messages.
295
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.
299
300   NOTE: The function you provide *must not* call any other libevent
301   functionality.  Doing so can produce undefined behavior.
302   */
303 void event_set_log_callback(event_log_cb cb);
304
305 /**
306  Override Libevent's behavior in the event of a fatal internal error.
307
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.
313
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.
316  */
317 typedef void (*event_fatal_cb)(int err);
318 void event_set_fatal_callback(event_fatal_cb cb);
319
320 /**
321   Associate a different event base with an event.
322
323   @param eb the event base
324   @param ev the event
325  */
326 int event_base_set(struct event_base *, struct event *);
327
328 /**
329  event_base_loop() flags
330  */
331 /*@{*/
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
338 /*@}*/
339
340 /**
341   Handle events (threadsafe version).
342
343   This is a more flexible version of event_base_dispatch().
344
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'
348   argument.
349
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
353     registered.
354   @see event_loopexit(), event_base_loop()
355   */
356 int event_base_loop(struct event_base *, int);
357
358 /**
359   Exit the event loop after the specified time (threadsafe variant).
360
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.
364
365   Subsequent invocations of event_base_loop() will proceed normally.
366
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()
371  */
372 int event_base_loopexit(struct event_base *, const struct timeval *);
373
374 /**
375   Abort the active event_base_loop() immediately.
376
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.
380
381   Subsequent invocations of event_loop() will proceed normally.
382
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
386  */
387 int event_base_loopbreak(struct event_base *);
388
389 /**
390   Checks if the event loop was told to exit by event_loopexit().
391
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.
394
395   @param eb the event_base structure returned by event_init()
396   @return true if event_base_loopexit() was called on this event base,
397     or 0 otherwise
398   @see event_base_loopexit
399   @see event_base_got_break
400  */
401 int event_base_got_exit(struct event_base *);
402
403 /**
404   Checks if the event loop was told to abort immediately by event_loopbreak().
405
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.
408
409   @param eb the event_base structure returned by event_init()
410   @return true if event_base_loopbreak() was called on this event base,
411     or 0 otherwise
412   @see event_base_loopbreak
413   @see event_base_got_exit
414  */
415 int event_base_got_break(struct event_base *);
416
417 /* Flags to pass to event_set(), event_new(), event_assign(),
418  * event_pending(), and anything else with an argument of the form
419  * "short events" */
420 #define EV_TIMEOUT      0x01
421 #define EV_READ         0x02
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. */
427 #define EV_ET       0x20
428
429 /**
430   Define a timer event.
431
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
436  */
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))
440
441 /**
442   Add a timer event.
443
444   @param ev the event struct
445   @param tv timeval struct
446  */
447 #define evtimer_add(ev, tv)             event_add((ev), (tv))
448
449 /**
450  * Delete a timer event.
451  *
452  * @param ev the event struct to be disabled
453  */
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)
457
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)
466
467 typedef void (*event_callback_fn)(evutil_socket_t, short, void *);
468
469 /**
470   Prepare an event structure to be added.
471
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.
480
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.
485
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.
491
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
498
499   @return 0 if success, or -1 on invalid arguments.
500
501   @see event_add(), event_del(), event_once()
502
503   */
504 int event_assign(struct event *, struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
505
506 /**
507   Create and allocate a new event structure, ready to be added.
508
509   Arguments are as for event_assign; returns a newly allocated struct event *
510   that must later be deallocated with event_free().
511
512  */
513 struct event *event_new(struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
514
515 /**
516    Deallocate a struct event * returned by event_new().
517  */
518 void event_free(struct event *);
519
520 /**
521   Schedule a one-time event
522
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.
526
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 |
530          EV_WRITE
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
534          to wait forever
535   @return 0 if successful, or -1 if an error occurred
536   @see event_once()
537  */
538 int event_base_once(struct event_base *, evutil_socket_t, short, event_callback_fn, void *, const struct timeval *);
539
540 /**
541   Add an event to the set of monitored events.
542
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.
551
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
554          to wait forever
555   @return 0 if successful, or -1 if an error occurred
556   @see event_del(), event_set()
557   */
558 int event_add(struct event *, const struct timeval *);
559
560 /**
561   Remove an event from the set of monitored events.
562
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
565   effect.
566
567   @param ev an event struct to be removed from the working set
568   @return 0 if successful, or -1 if an error occurred
569   @see event_add()
570  */
571 int event_del(struct event *);
572
573
574 /**
575   Make an event active.
576
577   @param ev an event to make active.
578   @param res a set of flags to pass to the event's callback.
579   @param ncalls
580  **/
581 void event_active(struct event *, int, short);
582
583
584 /**
585   Checks if a specific event is pending or scheduled.
586
587   @param ev an event struct previously passed to event_add()
588   @param what the requested event type; any of EV_TIMEOUT|EV_READ|
589          EV_WRITE|EV_SIGNAL
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
592          expire.
593
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.
596
597  */
598 int event_pending(const struct event *, short, struct timeval *);
599
600
601 /**
602   Test if an event structure might be initialized.
603
604   The event_initialized() function can be used to check if an event has been
605   initialized.
606
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.
611
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
614           initialized
615  */
616 int event_initialized(const struct event *ev);
617
618 /**
619    Get the signal number assigned to an event.
620 */
621 #define event_get_signal(ev) ((int)event_get_fd(ev))
622
623 /**
624    Get the socket assigned to an event.
625 */
626 evutil_socket_t event_get_fd(const struct event *ev);
627
628 /**
629    Get the event_base assigned to an event.
630 */
631 struct event_base *event_get_base(const struct event *ev);
632
633 /**
634    Return the events (EV_READ, EV_WRITE, etc) assigned to an event.
635 */
636 short event_get_events(const struct event *ev);
637
638 /**
639    Return the callback assigned to an event.
640 */
641 event_callback_fn event_get_callback(const struct event *ev);
642
643 /**
644    Return the callback argument assigned to an event.
645 */
646 void *event_get_callback_arg(const struct event *ev);
647
648 /**
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
651    on.
652
653    If any of the "_out" arguments is NULL, it will be ignored.
654  */
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);
658
659 /**
660    Return the size of struct event that the Libevent library was compiled
661    with.
662
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
665    otherwise might not.
666
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.
671  */
672 size_t event_get_struct_event_size(void);
673
674 /**
675    Get the Libevent version.
676
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
679    compiled against.
680
681    @return a string containing the version number of Libevent
682 */
683 const char *event_get_version(void);
684
685 /**
686    Return a numeric representation of Libevent's version.
687
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
690    compile.
691
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
695 */
696 ev_uint32_t event_get_version_number(void);
697
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
701  * headers. */
702 #define LIBEVENT_VERSION_NUMBER _EVENT_NUMERIC_VERSION
703
704 #define EVENT_MAX_PRIORITIES 256
705 /**
706   Set the number of different event priorities (threadsafe variant).
707
708   See the description of event_priority_init() for more information.
709
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()
714  */
715 int     event_base_priority_init(struct event_base *, int);
716
717
718 /**
719   Assign a priority to an event.
720
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()
725   */
726 int     event_priority_set(struct event *, int);
727
728 /**
729    Prepare Libevent to use a large number of timeouts with the same duration.
730
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
736    Libevent about it.
737
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.
742
743    (This optimization probably will not be worthwhile until you have thousands
744    or tens of thousands of events with the same timeout.)
745  */
746 const struct timeval *event_base_init_common_timeout(struct event_base *base,
747     const struct timeval *duration);
748
749 #ifndef _EVENT_DISABLE_MM_REPLACEMENT
750 /**
751  Override the functions that Libevent uses for memory management.
752
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.
757
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
762  that you provided.
763
764  @param malloc_fn A replacement for malloc.
765  @param realloc_fn A replacement for realloc
766  @param free_fn A replacement for free.
767  **/
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
773 #endif
774
775 void event_base_dump_events(struct event_base *, FILE *);
776
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
780     cached time.
781
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.
785
786     Returns 0 on success, negative on failure.
787  */
788 int event_base_gettimeofday_cached(struct event_base *base,
789     struct timeval *tv);
790
791 #ifdef __cplusplus
792 }
793 #endif
794
795 #endif /* _EVENT2_EVENT_H_ */