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 
00572 /* Obsolete names: these are deprecated, but older programs might use them.
00573  * They violate the reserved-identifier namespace. */
00574 #define _EVENT_LOG_DEBUG EVENT_LOG_DEBUG
00575 #define _EVENT_LOG_MSG EVENT_LOG_MSG
00576 #define _EVENT_LOG_WARN EVENT_LOG_WARN
00577 #define _EVENT_LOG_ERR EVENT_LOG_ERR
00578 
00584 typedef void (*event_log_cb)(int severity, const char *msg);
00595 void event_set_log_callback(event_log_cb cb);
00596 
00602 typedef void (*event_fatal_cb)(int err);
00603 
00616 void event_set_fatal_callback(event_fatal_cb cb);
00617 
00627 int event_base_set(struct event_base *, struct event *);
00628 
00636 #define EVLOOP_ONCE     0x01
00637 
00639 #define EVLOOP_NONBLOCK 0x02
00640 
00660 int event_base_loop(struct event_base *, int);
00661 
00677 int event_base_loopexit(struct event_base *, const struct timeval *);
00678 
00692 int event_base_loopbreak(struct event_base *);
00693 
00706 int event_base_got_exit(struct event_base *);
00707 
00720 int event_base_got_break(struct event_base *);
00721 
00731 #define EV_TIMEOUT      0x01
00732 
00733 #define EV_READ         0x02
00734 
00735 #define EV_WRITE        0x04
00736 
00737 #define EV_SIGNAL       0x08
00738 
00744 #define EV_PERSIST      0x10
00745 
00746 #define EV_ET       0x20
00747 
00754 #define evtimer_assign(ev, b, cb, arg) \
00755         event_assign((ev), (b), -1, 0, (cb), (arg))
00756 #define evtimer_new(b, cb, arg)        event_new((b), -1, 0, (cb), (arg))
00757 #define evtimer_add(ev, tv)             event_add((ev), (tv))
00758 #define evtimer_del(ev)                 event_del(ev)
00759 #define evtimer_pending(ev, tv)         event_pending((ev), EV_TIMEOUT, (tv))
00760 #define evtimer_initialized(ev)         event_initialized(ev)
00761 
00769 #define evsignal_add(ev, tv)            event_add((ev), (tv))
00770 #define evsignal_assign(ev, b, x, cb, arg)                      \
00771         event_assign((ev), (b), (x), EV_SIGNAL|EV_PERSIST, cb, (arg))
00772 #define evsignal_new(b, x, cb, arg)                             \
00773         event_new((b), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
00774 #define evsignal_del(ev)                event_del(ev)
00775 #define evsignal_pending(ev, tv)        event_pending((ev), EV_SIGNAL, (tv))
00776 #define evsignal_initialized(ev)        event_initialized(ev)
00777 
00790 typedef void (*event_callback_fn)(evutil_socket_t, short, void *);
00791 
00840 struct event *event_new(struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
00841 
00842 
00881 int event_assign(struct event *, struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
00882 
00889 void event_free(struct event *);
00890 
00913 int event_base_once(struct event_base *, evutil_socket_t, short, event_callback_fn, void *, const struct timeval *);
00914 
00937 int event_add(struct event *ev, const struct timeval *timeout);
00938 
00950 int event_del(struct event *);
00951 
00952 
00967 void event_active(struct event *ev, int res, short ncalls);
00968 
00982 int event_pending(const struct event *ev, short events, struct timeval *tv);
00983 
00984 
01000 int event_initialized(const struct event *ev);
01001 
01005 #define event_get_signal(ev) ((int)event_get_fd(ev))
01006 
01011 evutil_socket_t event_get_fd(const struct event *ev);
01012 
01016 struct event_base *event_get_base(const struct event *ev);
01017 
01021 short event_get_events(const struct event *ev);
01022 
01026 event_callback_fn event_get_callback(const struct event *ev);
01027 
01031 void *event_get_callback_arg(const struct event *ev);
01032 
01040 void event_get_assignment(const struct event *event,
01041     struct event_base **base_out, evutil_socket_t *fd_out, short *events_out,
01042     event_callback_fn *callback_out, void **arg_out);
01043 
01057 size_t event_get_struct_event_size(void);
01058 
01068 const char *event_get_version(void);
01069 
01081 ev_uint32_t event_get_version_number(void);
01082 
01084 #define LIBEVENT_VERSION _EVENT_VERSION
01085 
01087 #define LIBEVENT_VERSION_NUMBER _EVENT_NUMERIC_VERSION
01088 
01090 #define EVENT_MAX_PRIORITIES 256
01091 
01118 int     event_base_priority_init(struct event_base *, int);
01119 
01128 int     event_priority_set(struct event *, int);
01129 
01149 const struct timeval *event_base_init_common_timeout(struct event_base *base,
01150     const struct timeval *duration);
01151 
01152 #if !defined(_EVENT_DISABLE_MM_REPLACEMENT) || defined(_EVENT_IN_DOXYGEN)
01153 
01175 void event_set_mem_functions(
01176         void *(*malloc_fn)(size_t sz),
01177         void *(*realloc_fn)(void *ptr, size_t sz),
01178         void (*free_fn)(void *ptr));
01181 #define EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
01182 #endif
01183 
01184 void event_base_dump_events(struct event_base *, FILE *);
01185 
01197 int event_base_gettimeofday_cached(struct event_base *base,
01198     struct timeval *tv);
01199 
01200 #ifdef __cplusplus
01201 }
01202 #endif
01203 
01204 #endif /* _EVENT2_EVENT_H_ */

Generated on 15 Apr 2015 for libevent by  doxygen 1.4.7