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