libevent
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-2012 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 
00183 #ifdef __cplusplus
00184 extern "C" {
00185 #endif
00186 
00187 #include <event2/event-config.h>
00188 #ifdef _EVENT_HAVE_SYS_TYPES_H
00189 #include <sys/types.h>
00190 #endif
00191 #ifdef _EVENT_HAVE_SYS_TIME_H
00192 #include <sys/time.h>
00193 #endif
00194 
00195 #include <stdio.h>
00196 
00197 /* For int types. */
00198 #include <event2/util.h>
00199 
00213 struct event_base
00214 #ifdef _EVENT_IN_DOXYGEN
00215 {/*Empty body so that doxygen will generate documentation here.*/}
00216 #endif
00217 ;
00218 
00272 struct event
00273 #ifdef _EVENT_IN_DOXYGEN
00274 {/*Empty body so that doxygen will generate documentation here.*/}
00275 #endif
00276 ;
00277 
00291 struct event_config
00292 #ifdef _EVENT_IN_DOXYGEN
00293 {/*Empty body so that doxygen will generate documentation here.*/}
00294 #endif
00295 ;
00296 
00317 void event_enable_debug_mode(void);
00318 
00328 void event_debug_unassign(struct event *);
00329 
00337 struct event_base *event_base_new(void);
00338 
00349 int event_reinit(struct event_base *base);
00350 
00364 int event_base_dispatch(struct event_base *);
00365 
00372 const char *event_base_get_method(const struct event_base *);
00373 
00386 const char **event_get_supported_methods(void);
00387 
00398 struct event_config *event_config_new(void);
00399 
00405 void event_config_free(struct event_config *cfg);
00406 
00419 int event_config_avoid_method(struct event_config *cfg, const char *method);
00420 
00430 enum event_method_feature {
00432     EV_FEATURE_ET = 0x01,
00437     EV_FEATURE_O1 = 0x02,
00440     EV_FEATURE_FDS = 0x04
00441 };
00442 
00451 enum event_base_config_flag {
00454         EVENT_BASE_FLAG_NOLOCK = 0x01,
00457         EVENT_BASE_FLAG_IGNORE_ENV = 0x02,
00464         EVENT_BASE_FLAG_STARTUP_IOCP = 0x04,
00468         EVENT_BASE_FLAG_NO_CACHE_TIME = 0x08,
00469 
00484         EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST = 0x10
00485 };
00486 
00494 int event_base_get_features(const struct event_base *base);
00495 
00518 int event_config_require_features(struct event_config *cfg, int feature);
00519 
00526 int event_config_set_flag(struct event_config *cfg, int flag);
00527 
00537 int event_config_set_num_cpus_hint(struct event_config *cfg, int cpus);
00538 
00551 struct event_base *event_base_new_with_config(const struct event_config *);
00552 
00561 void event_base_free(struct event_base *);
00562 
00566 #define _EVENT_LOG_DEBUG 0
00567 #define _EVENT_LOG_MSG   1
00568 #define _EVENT_LOG_WARN  2
00569 #define _EVENT_LOG_ERR   3
00570 
00577 typedef void (*event_log_cb)(int severity, const char *msg);
00588 void event_set_log_callback(event_log_cb cb);
00589 
00595 typedef void (*event_fatal_cb)(int err);
00596 
00609 void event_set_fatal_callback(event_fatal_cb cb);
00610 
00620 int event_base_set(struct event_base *, struct event *);
00621 
00629 #define EVLOOP_ONCE     0x01
00630 
00632 #define EVLOOP_NONBLOCK 0x02
00633 
00653 int event_base_loop(struct event_base *, int);
00654 
00670 int event_base_loopexit(struct event_base *, const struct timeval *);
00671 
00685 int event_base_loopbreak(struct event_base *);
00686 
00699 int event_base_got_exit(struct event_base *);
00700 
00713 int event_base_got_break(struct event_base *);
00714 
00724 #define EV_TIMEOUT      0x01
00725 
00726 #define EV_READ         0x02
00727 
00728 #define EV_WRITE        0x04
00729 
00730 #define EV_SIGNAL       0x08
00731 
00737 #define EV_PERSIST      0x10
00738 
00739 #define EV_ET       0x20
00740 
00747 #define evtimer_assign(ev, b, cb, arg) \
00748         event_assign((ev), (b), -1, 0, (cb), (arg))
00749 #define evtimer_new(b, cb, arg)        event_new((b), -1, 0, (cb), (arg))
00750 #define evtimer_add(ev, tv)             event_add((ev), (tv))
00751 #define evtimer_del(ev)                 event_del(ev)
00752 #define evtimer_pending(ev, tv)         event_pending((ev), EV_TIMEOUT, (tv))
00753 #define evtimer_initialized(ev)         event_initialized(ev)
00754 
00762 #define evsignal_add(ev, tv)            event_add((ev), (tv))
00763 #define evsignal_assign(ev, b, x, cb, arg)                      \
00764         event_assign((ev), (b), (x), EV_SIGNAL|EV_PERSIST, cb, (arg))
00765 #define evsignal_new(b, x, cb, arg)                             \
00766         event_new((b), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
00767 #define evsignal_del(ev)                event_del(ev)
00768 #define evsignal_pending(ev, tv)        event_pending((ev), EV_SIGNAL, (tv))
00769 #define evsignal_initialized(ev)        event_initialized(ev)
00770 
00783 typedef void (*event_callback_fn)(evutil_socket_t, short, void *);
00784 
00833 struct event *event_new(struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
00834 
00835 
00874 int event_assign(struct event *, struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
00875 
00882 void event_free(struct event *);
00883 
00906 int event_base_once(struct event_base *, evutil_socket_t, short, event_callback_fn, void *, const struct timeval *);
00907 
00930 int event_add(struct event *ev, const struct timeval *timeout);
00931 
00943 int event_del(struct event *);
00944 
00945 
00960 void event_active(struct event *ev, int res, short ncalls);
00961 
00975 int event_pending(const struct event *ev, short events, struct timeval *tv);
00976 
00977 
00993 int event_initialized(const struct event *ev);
00994 
00998 #define event_get_signal(ev) ((int)event_get_fd(ev))
00999 
01004 evutil_socket_t event_get_fd(const struct event *ev);
01005 
01009 struct event_base *event_get_base(const struct event *ev);
01010 
01014 short event_get_events(const struct event *ev);
01015 
01019 event_callback_fn event_get_callback(const struct event *ev);
01020 
01024 void *event_get_callback_arg(const struct event *ev);
01025 
01033 void event_get_assignment(const struct event *event,
01034     struct event_base **base_out, evutil_socket_t *fd_out, short *events_out,
01035     event_callback_fn *callback_out, void **arg_out);
01036 
01050 size_t event_get_struct_event_size(void);
01051 
01061 const char *event_get_version(void);
01062 
01074 ev_uint32_t event_get_version_number(void);
01075 
01077 #define LIBEVENT_VERSION _EVENT_VERSION
01078 
01080 #define LIBEVENT_VERSION_NUMBER _EVENT_NUMERIC_VERSION
01081 
01083 #define EVENT_MAX_PRIORITIES 256
01084 
01111 int     event_base_priority_init(struct event_base *, int);
01112 
01121 int     event_priority_set(struct event *, int);
01122 
01142 const struct timeval *event_base_init_common_timeout(struct event_base *base,
01143     const struct timeval *duration);
01144 
01145 #if !defined(_EVENT_DISABLE_MM_REPLACEMENT) || defined(_EVENT_IN_DOXYGEN)
01146 
01168 void event_set_mem_functions(
01169         void *(*malloc_fn)(size_t sz),
01170         void *(*realloc_fn)(void *ptr, size_t sz),
01171         void (*free_fn)(void *ptr));
01174 #define EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
01175 #endif
01176 
01177 void event_base_dump_events(struct event_base *, FILE *);
01178 
01190 int event_base_gettimeofday_cached(struct event_base *base,
01191     struct timeval *tv);
01192 
01193 #ifdef __cplusplus
01194 }
01195 #endif
01196 
01197 #endif /* _EVENT2_EVENT_H_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines