1*c43e99fdSEd Maste /*
2*c43e99fdSEd Maste  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3*c43e99fdSEd Maste  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4*c43e99fdSEd Maste  *
5*c43e99fdSEd Maste  * Redistribution and use in source and binary forms, with or without
6*c43e99fdSEd Maste  * modification, are permitted provided that the following conditions
7*c43e99fdSEd Maste  * are met:
8*c43e99fdSEd Maste  * 1. Redistributions of source code must retain the above copyright
9*c43e99fdSEd Maste  *    notice, this list of conditions and the following disclaimer.
10*c43e99fdSEd Maste  * 2. Redistributions in binary form must reproduce the above copyright
11*c43e99fdSEd Maste  *    notice, this list of conditions and the following disclaimer in the
12*c43e99fdSEd Maste  *    documentation and/or other materials provided with the distribution.
13*c43e99fdSEd Maste  * 3. The name of the author may not be used to endorse or promote products
14*c43e99fdSEd Maste  *    derived from this software without specific prior written permission.
15*c43e99fdSEd Maste  *
16*c43e99fdSEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17*c43e99fdSEd Maste  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18*c43e99fdSEd Maste  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*c43e99fdSEd Maste  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20*c43e99fdSEd Maste  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21*c43e99fdSEd Maste  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22*c43e99fdSEd Maste  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23*c43e99fdSEd Maste  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24*c43e99fdSEd Maste  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25*c43e99fdSEd Maste  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*c43e99fdSEd Maste  */
27*c43e99fdSEd Maste #ifndef EVENT2_EVENT_STRUCT_H_INCLUDED_
28*c43e99fdSEd Maste #define EVENT2_EVENT_STRUCT_H_INCLUDED_
29*c43e99fdSEd Maste 
30*c43e99fdSEd Maste /** @file event2/event_struct.h
31*c43e99fdSEd Maste 
32*c43e99fdSEd Maste   Structures used by event.h.  Using these structures directly WILL harm
33*c43e99fdSEd Maste   forward compatibility: be careful.
34*c43e99fdSEd Maste 
35*c43e99fdSEd Maste   No field declared in this file should be used directly in user code.  Except
36*c43e99fdSEd Maste   for historical reasons, these fields would not be exposed at all.
37*c43e99fdSEd Maste  */
38*c43e99fdSEd Maste 
39*c43e99fdSEd Maste #ifdef __cplusplus
40*c43e99fdSEd Maste extern "C" {
41*c43e99fdSEd Maste #endif
42*c43e99fdSEd Maste 
43*c43e99fdSEd Maste #include <event2/event-config.h>
44*c43e99fdSEd Maste #ifdef EVENT__HAVE_SYS_TYPES_H
45*c43e99fdSEd Maste #include <sys/types.h>
46*c43e99fdSEd Maste #endif
47*c43e99fdSEd Maste #ifdef EVENT__HAVE_SYS_TIME_H
48*c43e99fdSEd Maste #include <sys/time.h>
49*c43e99fdSEd Maste #endif
50*c43e99fdSEd Maste 
51*c43e99fdSEd Maste /* For int types. */
52*c43e99fdSEd Maste #include <event2/util.h>
53*c43e99fdSEd Maste 
54*c43e99fdSEd Maste /* For evkeyvalq */
55*c43e99fdSEd Maste #include <event2/keyvalq_struct.h>
56*c43e99fdSEd Maste 
57*c43e99fdSEd Maste #define EVLIST_TIMEOUT	    0x01
58*c43e99fdSEd Maste #define EVLIST_INSERTED	    0x02
59*c43e99fdSEd Maste #define EVLIST_SIGNAL	    0x04
60*c43e99fdSEd Maste #define EVLIST_ACTIVE	    0x08
61*c43e99fdSEd Maste #define EVLIST_INTERNAL	    0x10
62*c43e99fdSEd Maste #define EVLIST_ACTIVE_LATER 0x20
63*c43e99fdSEd Maste #define EVLIST_FINALIZING   0x40
64*c43e99fdSEd Maste #define EVLIST_INIT	    0x80
65*c43e99fdSEd Maste 
66*c43e99fdSEd Maste #define EVLIST_ALL          0xff
67*c43e99fdSEd Maste 
68*c43e99fdSEd Maste /* Fix so that people don't have to run with <sys/queue.h> */
69*c43e99fdSEd Maste #ifndef TAILQ_ENTRY
70*c43e99fdSEd Maste #define EVENT_DEFINED_TQENTRY_
71*c43e99fdSEd Maste #define TAILQ_ENTRY(type)						\
72*c43e99fdSEd Maste struct {								\
73*c43e99fdSEd Maste 	struct type *tqe_next;	/* next element */			\
74*c43e99fdSEd Maste 	struct type **tqe_prev;	/* address of previous next element */	\
75*c43e99fdSEd Maste }
76*c43e99fdSEd Maste #endif /* !TAILQ_ENTRY */
77*c43e99fdSEd Maste 
78*c43e99fdSEd Maste #ifndef TAILQ_HEAD
79*c43e99fdSEd Maste #define EVENT_DEFINED_TQHEAD_
80*c43e99fdSEd Maste #define TAILQ_HEAD(name, type)			\
81*c43e99fdSEd Maste struct name {					\
82*c43e99fdSEd Maste 	struct type *tqh_first;			\
83*c43e99fdSEd Maste 	struct type **tqh_last;			\
84*c43e99fdSEd Maste }
85*c43e99fdSEd Maste #endif
86*c43e99fdSEd Maste 
87*c43e99fdSEd Maste /* Fix so that people don't have to run with <sys/queue.h> */
88*c43e99fdSEd Maste #ifndef LIST_ENTRY
89*c43e99fdSEd Maste #define EVENT_DEFINED_LISTENTRY_
90*c43e99fdSEd Maste #define LIST_ENTRY(type)						\
91*c43e99fdSEd Maste struct {								\
92*c43e99fdSEd Maste 	struct type *le_next;	/* next element */			\
93*c43e99fdSEd Maste 	struct type **le_prev;	/* address of previous next element */	\
94*c43e99fdSEd Maste }
95*c43e99fdSEd Maste #endif /* !LIST_ENTRY */
96*c43e99fdSEd Maste 
97*c43e99fdSEd Maste #ifndef LIST_HEAD
98*c43e99fdSEd Maste #define EVENT_DEFINED_LISTHEAD_
99*c43e99fdSEd Maste #define LIST_HEAD(name, type)						\
100*c43e99fdSEd Maste struct name {								\
101*c43e99fdSEd Maste 	struct type *lh_first;  /* first element */			\
102*c43e99fdSEd Maste 	}
103*c43e99fdSEd Maste #endif /* !LIST_HEAD */
104*c43e99fdSEd Maste 
105*c43e99fdSEd Maste struct event;
106*c43e99fdSEd Maste 
107*c43e99fdSEd Maste struct event_callback {
108*c43e99fdSEd Maste 	TAILQ_ENTRY(event_callback) evcb_active_next;
109*c43e99fdSEd Maste 	short evcb_flags;
110*c43e99fdSEd Maste 	ev_uint8_t evcb_pri;	/* smaller numbers are higher priority */
111*c43e99fdSEd Maste 	ev_uint8_t evcb_closure;
112*c43e99fdSEd Maste 	/* allows us to adopt for different types of events */
113*c43e99fdSEd Maste         union {
114*c43e99fdSEd Maste 		void (*evcb_callback)(evutil_socket_t, short, void *);
115*c43e99fdSEd Maste 		void (*evcb_selfcb)(struct event_callback *, void *);
116*c43e99fdSEd Maste 		void (*evcb_evfinalize)(struct event *, void *);
117*c43e99fdSEd Maste 		void (*evcb_cbfinalize)(struct event_callback *, void *);
118*c43e99fdSEd Maste 	} evcb_cb_union;
119*c43e99fdSEd Maste 	void *evcb_arg;
120*c43e99fdSEd Maste };
121*c43e99fdSEd Maste 
122*c43e99fdSEd Maste struct event_base;
123*c43e99fdSEd Maste struct event {
124*c43e99fdSEd Maste 	struct event_callback ev_evcallback;
125*c43e99fdSEd Maste 
126*c43e99fdSEd Maste 	/* for managing timeouts */
127*c43e99fdSEd Maste 	union {
128*c43e99fdSEd Maste 		TAILQ_ENTRY(event) ev_next_with_common_timeout;
129*c43e99fdSEd Maste 		int min_heap_idx;
130*c43e99fdSEd Maste 	} ev_timeout_pos;
131*c43e99fdSEd Maste 	evutil_socket_t ev_fd;
132*c43e99fdSEd Maste 
133*c43e99fdSEd Maste 	struct event_base *ev_base;
134*c43e99fdSEd Maste 
135*c43e99fdSEd Maste 	union {
136*c43e99fdSEd Maste 		/* used for io events */
137*c43e99fdSEd Maste 		struct {
138*c43e99fdSEd Maste 			LIST_ENTRY (event) ev_io_next;
139*c43e99fdSEd Maste 			struct timeval ev_timeout;
140*c43e99fdSEd Maste 		} ev_io;
141*c43e99fdSEd Maste 
142*c43e99fdSEd Maste 		/* used by signal events */
143*c43e99fdSEd Maste 		struct {
144*c43e99fdSEd Maste 			LIST_ENTRY (event) ev_signal_next;
145*c43e99fdSEd Maste 			short ev_ncalls;
146*c43e99fdSEd Maste 			/* Allows deletes in callback */
147*c43e99fdSEd Maste 			short *ev_pncalls;
148*c43e99fdSEd Maste 		} ev_signal;
149*c43e99fdSEd Maste 	} ev_;
150*c43e99fdSEd Maste 
151*c43e99fdSEd Maste 	short ev_events;
152*c43e99fdSEd Maste 	short ev_res;		/* result passed to event callback */
153*c43e99fdSEd Maste 	struct timeval ev_timeout;
154*c43e99fdSEd Maste };
155*c43e99fdSEd Maste 
156*c43e99fdSEd Maste TAILQ_HEAD (event_list, event);
157*c43e99fdSEd Maste 
158*c43e99fdSEd Maste #ifdef EVENT_DEFINED_TQENTRY_
159*c43e99fdSEd Maste #undef TAILQ_ENTRY
160*c43e99fdSEd Maste #endif
161*c43e99fdSEd Maste 
162*c43e99fdSEd Maste #ifdef EVENT_DEFINED_TQHEAD_
163*c43e99fdSEd Maste #undef TAILQ_HEAD
164*c43e99fdSEd Maste #endif
165*c43e99fdSEd Maste 
166*c43e99fdSEd Maste LIST_HEAD (event_dlist, event);
167*c43e99fdSEd Maste 
168*c43e99fdSEd Maste #ifdef EVENT_DEFINED_LISTENTRY_
169*c43e99fdSEd Maste #undef LIST_ENTRY
170*c43e99fdSEd Maste #endif
171*c43e99fdSEd Maste 
172*c43e99fdSEd Maste #ifdef EVENT_DEFINED_LISTHEAD_
173*c43e99fdSEd Maste #undef LIST_HEAD
174*c43e99fdSEd Maste #endif
175*c43e99fdSEd Maste 
176*c43e99fdSEd Maste #ifdef __cplusplus
177*c43e99fdSEd Maste }
178*c43e99fdSEd Maste #endif
179*c43e99fdSEd Maste 
180*c43e99fdSEd Maste #endif /* EVENT2_EVENT_STRUCT_H_INCLUDED_ */
181