libevent
|
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_STRUCT_H_ 00028 #define _EVENT2_EVENT_STRUCT_H_ 00029 00037 #ifdef __cplusplus 00038 extern "C" { 00039 #endif 00040 00041 #include <event2/event-config.h> 00042 #ifdef _EVENT_HAVE_SYS_TYPES_H 00043 #include <sys/types.h> 00044 #endif 00045 #ifdef _EVENT_HAVE_SYS_TIME_H 00046 #include <sys/time.h> 00047 #endif 00048 00049 /* For int types. */ 00050 #include <event2/util.h> 00051 00052 /* For evkeyvalq */ 00053 #include <event2/keyvalq_struct.h> 00054 00055 #define EVLIST_TIMEOUT 0x01 00056 #define EVLIST_INSERTED 0x02 00057 #define EVLIST_SIGNAL 0x04 00058 #define EVLIST_ACTIVE 0x08 00059 #define EVLIST_INTERNAL 0x10 00060 #define EVLIST_INIT 0x80 00061 00062 /* EVLIST_X_ Private space: 0x1000-0xf000 */ 00063 #define EVLIST_ALL (0xf000 | 0x9f) 00064 00065 /* Fix so that people don't have to run with <sys/queue.h> */ 00066 #ifndef TAILQ_ENTRY 00067 #define _EVENT_DEFINED_TQENTRY 00068 #define TAILQ_ENTRY(type) \ 00069 struct { \ 00070 struct type *tqe_next; /* next element */ \ 00071 struct type **tqe_prev; /* address of previous next element */ \ 00072 } 00073 #endif /* !TAILQ_ENTRY */ 00074 00075 #ifndef TAILQ_HEAD 00076 #define _EVENT_DEFINED_TQHEAD 00077 #define TAILQ_HEAD(name, type) \ 00078 struct name { \ 00079 struct type *tqh_first; \ 00080 struct type **tqh_last; \ 00081 } 00082 #endif 00083 00084 struct event_base; 00085 struct event { 00086 TAILQ_ENTRY(event) ev_active_next; 00087 TAILQ_ENTRY(event) ev_next; 00088 /* for managing timeouts */ 00089 union { 00090 TAILQ_ENTRY(event) ev_next_with_common_timeout; 00091 int min_heap_idx; 00092 } ev_timeout_pos; 00093 evutil_socket_t ev_fd; 00094 00095 struct event_base *ev_base; 00096 00097 union { 00098 /* used for io events */ 00099 struct { 00100 TAILQ_ENTRY(event) ev_io_next; 00101 struct timeval ev_timeout; 00102 } ev_io; 00103 00104 /* used by signal events */ 00105 struct { 00106 TAILQ_ENTRY(event) ev_signal_next; 00107 short ev_ncalls; 00108 /* Allows deletes in callback */ 00109 short *ev_pncalls; 00110 } ev_signal; 00111 } _ev; 00112 00113 short ev_events; 00114 short ev_res; /* result passed to event callback */ 00115 short ev_flags; 00116 ev_uint8_t ev_pri; /* smaller numbers are higher priority */ 00117 ev_uint8_t ev_closure; 00118 struct timeval ev_timeout; 00119 00120 /* allows us to adopt for different types of events */ 00121 void (*ev_callback)(evutil_socket_t, short, void *arg); 00122 void *ev_arg; 00123 }; 00124 00125 TAILQ_HEAD (event_list, event); 00126 00127 #ifdef _EVENT_DEFINED_TQENTRY 00128 #undef TAILQ_ENTRY 00129 #endif 00130 00131 #ifdef _EVENT_DEFINED_TQHEAD 00132 #undef TAILQ_HEAD 00133 #endif 00134 00135 #ifdef __cplusplus 00136 } 00137 #endif 00138 00139 #endif /* _EVENT2_EVENT_STRUCT_H_ */