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