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 <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 #ifdef WIN32
00054 #define WIN32_LEAN_AND_MEAN
00055 #include <windows.h>
00056 #undef WIN32_LEAN_AND_MEAN
00057 #endif
00058
00059 struct event_base;
00060 struct event;
00061 struct event_config;
00062
00073 struct event_base *event_base_new(void);
00074
00085 int event_reinit(struct event_base *base);
00086
00093 int event_base_dispatch(struct event_base *);
00094
00101 const char *event_base_get_method(struct event_base *);
00102
00115 const char **event_get_supported_methods(void);
00116
00127 struct event_config *event_config_new(void);
00128
00134 void event_config_free(struct event_config *cfg);
00135
00147 int event_config_avoid_method(struct event_config *cfg, const char *method);
00148
00149 enum event_method_feature {
00150
00151 EV_FEATURE_ET = 0x01,
00152
00153
00154
00155
00156 EV_FEATURE_O1 = 0x02,
00157
00158
00159 EV_FEATURE_FDS = 0x04,
00160 };
00161
00162 enum event_base_config_flag {
00163 EVENT_BASE_FLAG_NOLOCK = 0x01,
00164 };
00165
00169 enum event_method_feature event_base_get_features(struct event_base *base);
00170
00192 int event_config_require_features(struct event_config *cfg,
00193 enum event_method_feature feature);
00194
00197 int event_config_set_flag(struct event_config *cfg,
00198 enum event_base_config_flag flag);
00199
00212 struct event_base *event_base_new_with_config(struct event_config *cfg);
00213
00222 void event_base_free(struct event_base *);
00223
00224 #define _EVENT_LOG_DEBUG 0
00225 #define _EVENT_LOG_MSG 1
00226 #define _EVENT_LOG_WARN 2
00227 #define _EVENT_LOG_ERR 3
00228 typedef void (*event_log_cb)(int severity, const char *msg);
00236 void event_set_log_callback(event_log_cb cb);
00237
00244 int event_base_set(struct event_base *, struct event *);
00245
00250 #define EVLOOP_ONCE 0x01
00251 #define EVLOOP_NONBLOCK 0x02
00253
00254
00265 int event_base_loop(struct event_base *, int);
00266
00281 int event_base_loopexit(struct event_base *, const struct timeval *);
00282
00296 int event_base_loopbreak(struct event_base *);
00297
00298
00299
00300
00301 #define EV_TIMEOUT 0x01
00302 #define EV_READ 0x02
00303 #define EV_WRITE 0x04
00304 #define EV_SIGNAL 0x08
00305
00306 #define EV_PERSIST 0x10
00307
00308 #define EV_ET 0x20
00309
00317 #define evtimer_set(ev, cb, arg) event_set(ev, -1, 0, cb, arg)
00318 #define evtimer_assign(ev, b, cb, arg) event_assign(ev, b, -1, 0, cb, arg)
00319 #define evtimer_new(b, cb, arg) event_new(b, -1, 0, cb, arg)
00320
00327 #define evtimer_add(ev, tv) event_add(ev, tv)
00328
00334 #define evtimer_del(ev) event_del(ev)
00335 #define evtimer_pending(ev, tv) event_pending(ev, EV_TIMEOUT, tv)
00336 #define evtimer_initialized(ev) _event_initialized((ev), 0)
00337
00338 #define evsignal_add(ev, tv) event_add(ev, tv)
00339 #define evsignal_set(ev, x, cb, arg) \
00340 event_set(ev, x, EV_SIGNAL|EV_PERSIST, cb, arg)
00341 #define evsignal_assign(ev, b, x, cb, arg) \
00342 event_assign(ev, b, x, EV_SIGNAL|EV_PERSIST, cb, arg)
00343 #define evsignal_new(b, x, cb, arg) \
00344 event_new(b, x, EV_SIGNAL|EV_PERSIST, cb, arg)
00345 #define evsignal_del(ev) event_del(ev)
00346 #define evsignal_pending(ev, tv) event_pending(ev, EV_SIGNAL, tv)
00347 #define evsignal_initialized(ev) _event_initialized((ev), 0)
00348
00383 void event_set(struct event *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *);
00384
00385
00419 void event_assign(struct event *, struct event_base *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *);
00420
00428 struct event *event_new(struct event_base *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *);
00429
00433 void event_free(struct event *);
00434
00453 int event_base_once(struct event_base *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *, const struct timeval *);
00454
00473 int event_add(struct event *, const struct timeval *);
00474
00486 int event_del(struct event *);
00487
00488
00496 void event_active(struct event *, int, short);
00497
00498
00510 int event_pending(struct event *, short, struct timeval *);
00511
00512
00523 #define event_initialized(ev) _event_initialized((ev), 1)
00524
00525 int _event_initialized(struct event *, int check_fd);
00526
00530 #define event_get_signal(ev) ((int)event_get_fd(ev))
00531
00535 evutil_socket_t event_get_fd(struct event *ev);
00536
00537 #ifndef EVENT_FD
00538
00539
00540
00541 #define EVENT_FD(ev) ((int)event_get_fd(ev))
00542 #define EVENT_SIGNAL(ev) ((int)event_get_fd(ev))
00543 #endif
00544
00554 const char *event_get_version(void);
00555
00567 ev_uint32_t event_get_version_number(void);
00568
00570 #define LIBEVENT_VERSION _EVENT_VERSION
00571
00573 #define LIBEVENT_VERSION_NUMBER _EVENT_NUMERIC_VERSION
00574
00585 int event_base_priority_init(struct event_base *, int);
00586
00587
00596 int event_priority_set(struct event *, int);
00597
00598 #ifndef _EVENT_DISABLE_MM_REPLACEMENT
00599
00616 void event_set_mem_functions(void *(*malloc_fn)(size_t sz),
00617 void *(*realloc_fn)(void *ptr, size_t sz),
00618 void (*free_fn)(void *ptr));
00619 #endif
00620
00621 void event_base_dump_events(struct event_base *, FILE *);
00622
00623 #ifdef __cplusplus
00624 }
00625 #endif
00626
00627 #endif