libevent

include/event2/event.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
00003  * Copyright (c) 2007-2010 Niels Provos and Nick Mathewson
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00017  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00018  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00019  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00020  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00021  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00022  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00023  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00025  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 #ifndef _EVENT2_EVENT_H_
00028 #define _EVENT2_EVENT_H_
00029 
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00040 #include <event2/event-config.h>
00041 #ifdef _EVENT_HAVE_SYS_TYPES_H
00042 #include <sys/types.h>
00043 #endif
00044 #ifdef _EVENT_HAVE_SYS_TIME_H
00045 #include <sys/time.h>
00046 #endif
00047 
00048 #include <stdio.h>
00049 
00050 /* For int types. */
00051 #include <event2/util.h>
00052 
00053 struct event_base;
00054 struct event;
00055 struct event_config;
00056 
00074 void event_enable_debug_mode(void);
00075 
00083 void event_debug_unassign(struct event *);
00084 
00093 struct event_base *event_base_new(void);
00094 
00105 int event_reinit(struct event_base *base);
00106 
00113 int event_base_dispatch(struct event_base *);
00114 
00121 const char *event_base_get_method(const struct event_base *);
00122 
00135 const char **event_get_supported_methods(void);
00136 
00147 struct event_config *event_config_new(void);
00148 
00154 void event_config_free(struct event_config *cfg);
00155 
00167 int event_config_avoid_method(struct event_config *cfg, const char *method);
00168 
00169 enum event_method_feature {
00170     /* Require an event method that allows edge-triggered events with EV_ET. */
00171     EV_FEATURE_ET = 0x01,
00172     /* Require an event method where having one event triggered among
00173      * many is [approximately] an O(1) operation. This excludes (for
00174      * example) select and poll, which are approximately O(N) for N
00175      * equal to the total number of possible events. */
00176     EV_FEATURE_O1 = 0x02,
00177     /* Require an event method that allows file descriptors as well as
00178      * sockets. */
00179     EV_FEATURE_FDS = 0x04
00180 };
00181 
00182 enum event_base_config_flag {
00185         EVENT_BASE_FLAG_NOLOCK = 0x01,
00188         EVENT_BASE_FLAG_IGNORE_ENV = 0x02,
00190         EVENT_BASE_FLAG_STARTUP_IOCP = 0x04,
00194         EVENT_BASE_FLAG_NO_CACHE_TIME = 0x08,
00195 
00210         EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST = 0x10
00211 };
00212 
00216 int event_base_get_features(const struct event_base *base);
00217 
00239 int event_config_require_features(struct event_config *cfg, int feature);
00240 
00243 int event_config_set_flag(struct event_config *cfg, int flag);
00244 
00254 int event_config_set_num_cpus_hint(struct event_config *cfg, int cpus);
00255 
00268 struct event_base *event_base_new_with_config(const struct event_config *);
00269 
00278 void event_base_free(struct event_base *);
00279 
00280 #define _EVENT_LOG_DEBUG 0
00281 #define _EVENT_LOG_MSG   1
00282 #define _EVENT_LOG_WARN  2
00283 #define _EVENT_LOG_ERR   3
00284 
00285 /*
00286   A callback function used to intercept Libevent's log messages.
00287  */
00288 typedef void (*event_log_cb)(int severity, const char *msg);
00299 void event_set_log_callback(event_log_cb cb);
00300 
00313 typedef void (*event_fatal_cb)(int err);
00314 void event_set_fatal_callback(event_fatal_cb cb);
00315 
00322 int event_base_set(struct event_base *, struct event *);
00323 
00330 #define EVLOOP_ONCE     0x01
00331 
00333 #define EVLOOP_NONBLOCK 0x02
00334 
00347 int event_base_loop(struct event_base *, int);
00348 
00363 int event_base_loopexit(struct event_base *, const struct timeval *);
00364 
00378 int event_base_loopbreak(struct event_base *);
00379 
00392 int event_base_got_exit(struct event_base *);
00393 
00406 int event_base_got_break(struct event_base *);
00407 
00408 /* Flags to pass to event_set(), event_new(), event_assign(),
00409  * event_pending(), and anything else with an argument of the form
00410  * "short events" */
00411 #define EV_TIMEOUT      0x01
00412 #define EV_READ         0x02
00413 #define EV_WRITE        0x04
00414 #define EV_SIGNAL       0x08
00415 
00416 #define EV_PERSIST      0x10
00417 
00418 #define EV_ET       0x20
00419 
00428 #define evtimer_assign(ev, b, cb, arg) \
00429         event_assign((ev), (b), -1, 0, (cb), (arg))
00430 #define evtimer_new(b, cb, arg)        event_new((b), -1, 0, (cb), (arg))
00431 
00438 #define evtimer_add(ev, tv)             event_add((ev), (tv))
00439 
00445 #define evtimer_del(ev)                 event_del(ev)
00446 #define evtimer_pending(ev, tv)         event_pending((ev), EV_TIMEOUT, (tv))
00447 #define evtimer_initialized(ev)         event_initialized(ev)
00448 
00449 #define evsignal_add(ev, tv)            event_add((ev), (tv))
00450 #define evsignal_assign(ev, b, x, cb, arg)                      \
00451         event_assign((ev), (b), (x), EV_SIGNAL|EV_PERSIST, cb, (arg))
00452 #define evsignal_new(b, x, cb, arg)                             \
00453         event_new((b), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
00454 #define evsignal_del(ev)                event_del(ev)
00455 #define evsignal_pending(ev, tv)        event_pending((ev), EV_SIGNAL, (tv))
00456 #define evsignal_initialized(ev)        event_initialized(ev)
00457 
00458 typedef void (*event_callback_fn)(evutil_socket_t, short, void *);
00459 
00495 int event_assign(struct event *, struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
00496 
00504 struct event *event_new(struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
00505 
00509 void event_free(struct event *);
00510 
00529 int event_base_once(struct event_base *, evutil_socket_t, short, event_callback_fn, void *, const struct timeval *);
00530 
00549 int event_add(struct event *, const struct timeval *);
00550 
00562 int event_del(struct event *);
00563 
00564 
00572 void event_active(struct event *, int, short);
00573 
00574 
00589 int event_pending(const struct event *, short, struct timeval *);
00590 
00591 
00607 int event_initialized(const struct event *ev);
00608 
00612 #define event_get_signal(ev) ((int)event_get_fd(ev))
00613 
00617 evutil_socket_t event_get_fd(const struct event *ev);
00618 
00622 struct event_base *event_get_base(const struct event *ev);
00623 
00627 short event_get_events(const struct event *ev);
00628 
00632 event_callback_fn event_get_callback(const struct event *ev);
00633 
00637 void *event_get_callback_arg(const struct event *ev);
00638 
00646 void event_get_assignment(const struct event *event,
00647     struct event_base **base_out, evutil_socket_t *fd_out, short *events_out,
00648     event_callback_fn *callback_out, void **arg_out);
00649 
00663 size_t event_get_struct_event_size(void);
00664 
00674 const char *event_get_version(void);
00675 
00687 ev_uint32_t event_get_version_number(void);
00688 
00690 #define LIBEVENT_VERSION _EVENT_VERSION
00691 
00693 #define LIBEVENT_VERSION_NUMBER _EVENT_NUMERIC_VERSION
00694 
00695 #define EVENT_MAX_PRIORITIES 256
00696 
00706 int     event_base_priority_init(struct event_base *, int);
00707 
00708 
00717 int     event_priority_set(struct event *, int);
00718 
00737 const struct timeval *event_base_init_common_timeout(struct event_base *base,
00738     const struct timeval *duration);
00739 
00740 #ifndef _EVENT_DISABLE_MM_REPLACEMENT
00741 
00758 void event_set_mem_functions(
00759         void *(*malloc_fn)(size_t sz),
00760         void *(*realloc_fn)(void *ptr, size_t sz),
00761         void (*free_fn)(void *ptr));
00762 #define EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
00763 #endif
00764 
00765 void event_base_dump_events(struct event_base *, FILE *);
00766 
00778 int event_base_gettimeofday_cached(struct event_base *base,
00779     struct timeval *tv);
00780 
00781 #ifdef __cplusplus
00782 }
00783 #endif
00784 
00785 #endif /* _EVENT2_EVENT_H_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines