00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
00171 EV_FEATURE_ET = 0x01,
00172
00173
00174
00175
00176 EV_FEATURE_O1 = 0x02,
00177
00178
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
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
00409
00410
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