xref: /freebsd/lib/libc/include/isc/eventlib.h (revision cd0d51baaa4509a1db83251a601d34404d20c990)
1 /*-
2  * SPDX-License-Identifier: ISC
3  *
4  * Copyright (C) 2004, 2005, 2008  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 1995-1999, 2001, 2003  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* eventlib.h - exported interfaces for eventlib
21  * vix 09sep95 [initial]
22  *
23  * $Id: eventlib.h,v 1.7 2008/11/14 02:36:51 marka Exp $
24  */
25 
26 #ifndef _EVENTLIB_H
27 #define _EVENTLIB_H
28 
29 #include <sys/types.h>
30 #include <sys/uio.h>
31 #include <sys/time.h>
32 #include <stdio.h>
33 
34 #include <isc/platform.h>
35 
36 #ifndef __P
37 # define __EVENTLIB_P_DEFINED
38 # ifdef __STDC__
39 #  define __P(x) x
40 # else
41 #  define __P(x) ()
42 # endif
43 #endif
44 
45 /* In the absence of branded types... */
46 typedef struct { void *opaque; } evConnID;
47 typedef struct { void *opaque; } evFileID;
48 typedef struct { void *opaque; } evStreamID;
49 typedef struct { void *opaque; } evTimerID;
50 typedef struct { void *opaque; } evWaitID;
51 typedef struct { void *opaque; } evContext;
52 typedef struct { void *opaque; } evEvent;
53 
54 #define	evInitID(id) ((id)->opaque = NULL)
55 #define	evTestID(id) ((id).opaque != NULL)
56 
57 typedef void (*evConnFunc)__P((evContext, void *, int, const void *, int,
58 			       const void *, int));
59 typedef void (*evFileFunc)__P((evContext, void *, int, int));
60 typedef	void (*evStreamFunc)__P((evContext, void *, int, int));
61 typedef void (*evTimerFunc)__P((evContext, void *,
62 				struct timespec, struct timespec));
63 typedef	void (*evWaitFunc)__P((evContext, void *, const void *));
64 
65 typedef	struct { unsigned char mask[256/8]; } evByteMask;
66 #define	EV_BYTEMASK_BYTE(b) ((b) / 8)
67 #define	EV_BYTEMASK_MASK(b) (1 << ((b) % 8))
68 #define	EV_BYTEMASK_SET(bm, b) \
69 	((bm).mask[EV_BYTEMASK_BYTE(b)] |= EV_BYTEMASK_MASK(b))
70 #define	EV_BYTEMASK_CLR(bm, b) \
71 	((bm).mask[EV_BYTEMASK_BYTE(b)] &= ~EV_BYTEMASK_MASK(b))
72 #define	EV_BYTEMASK_TST(bm, b) \
73 	((bm).mask[EV_BYTEMASK_BYTE(b)] & EV_BYTEMASK_MASK(b))
74 
75 #define	EV_POLL		1
76 #define	EV_WAIT		2
77 #define	EV_NULL		4
78 
79 #define	EV_READ		1
80 #define	EV_WRITE	2
81 #define	EV_EXCEPT	4
82 
83 #define EV_WASNONBLOCKING 8	/* Internal library use. */
84 
85 /* eventlib.c */
86 #define evCreate	__evCreate
87 #define evSetDebug	__evSetDebug
88 #define evDestroy	__evDestroy
89 #define evGetNext	__evGetNext
90 #define evDispatch	__evDispatch
91 #define evDrop		__evDrop
92 #define evMainLoop	__evMainLoop
93 #define evHighestFD	__evHighestFD
94 #define evGetOption	__evGetOption
95 #define evSetOption	__evSetOption
96 
97 int  evCreate __P((evContext *));
98 void evSetDebug __P((evContext, int, FILE *));
99 int  evDestroy __P((evContext));
100 int  evGetNext __P((evContext, evEvent *, int));
101 int  evDispatch __P((evContext, evEvent));
102 void evDrop __P((evContext, evEvent));
103 int  evMainLoop __P((evContext));
104 int  evHighestFD __P((evContext));
105 int  evGetOption __P((evContext *, const char *, int *));
106 int  evSetOption __P((evContext *, const char *, int));
107 
108 /* ev_connects.c */
109 #define evListen	__evListen
110 #define evConnect	__evConnect
111 #define evCancelConn	__evCancelConn
112 #define evHold		__evHold
113 #define evUnhold	__evUnhold
114 #define evTryAccept	__evTryAccept
115 
116 int evListen __P((evContext, int, int, evConnFunc, void *, evConnID *));
117 int evConnect __P((evContext, int, const void *, int,
118 		   evConnFunc, void *, evConnID *));
119 int evCancelConn __P((evContext, evConnID));
120 int evHold __P((evContext, evConnID));
121 int evUnhold __P((evContext, evConnID));
122 int evTryAccept __P((evContext, evConnID, int *));
123 
124 /* ev_files.c */
125 #define evSelectFD	__evSelectFD
126 #define evDeselectFD	__evDeselectFD
127 
128 int evSelectFD __P((evContext, int, int, evFileFunc, void *, evFileID *));
129 int evDeselectFD __P((evContext, evFileID));
130 
131 /* ev_streams.c */
132 #define evConsIovec	__evConsIovec
133 #define evWrite		__evWrite
134 #define evRead		__evRead
135 #define evTimeRW	__evTimeRW
136 #define evUntimeRW	__evUntimeRW
137 #define	evCancelRW	__evCancelRW
138 
139 struct iovec evConsIovec __P((void *, size_t));
140 int evWrite __P((evContext, int, const struct iovec *, int,
141 		 evStreamFunc func, void *, evStreamID *));
142 int evRead __P((evContext, int, const struct iovec *, int,
143 		evStreamFunc func, void *, evStreamID *));
144 int evTimeRW __P((evContext, evStreamID, evTimerID timer));
145 int evUntimeRW __P((evContext, evStreamID));
146 int evCancelRW __P((evContext, evStreamID));
147 
148 /* ev_timers.c */
149 #define evConsTime	__evConsTime
150 #define evAddTime	__evAddTime
151 #define evSubTime	__evSubTime
152 #define evCmpTime	__evCmpTime
153 #define	evTimeSpec	__evTimeSpec
154 #define	evTimeVal	__evTimeVal
155 
156 #define evNowTime		__evNowTime
157 #define evUTCTime		__evUTCTime
158 #define evLastEventTime		__evLastEventTime
159 #define evSetTimer		__evSetTimer
160 #define evClearTimer		__evClearTimer
161 #define evConfigTimer		__evConfigTimer
162 #define evResetTimer		__evResetTimer
163 #define evSetIdleTimer		__evSetIdleTimer
164 #define evClearIdleTimer	__evClearIdleTimer
165 #define evResetIdleTimer	__evResetIdleTimer
166 #define evTouchIdleTimer	__evTouchIdleTimer
167 
168 struct timespec evConsTime __P((time_t sec, long nsec));
169 struct timespec evAddTime __P((struct timespec, struct timespec));
170 struct timespec evSubTime __P((struct timespec, struct timespec));
171 struct timespec evNowTime __P((void));
172 struct timespec evUTCTime __P((void));
173 struct timespec evLastEventTime __P((evContext));
174 struct timespec evTimeSpec __P((struct timeval));
175 struct timeval evTimeVal __P((struct timespec));
176 int evCmpTime __P((struct timespec, struct timespec));
177 int evSetTimer __P((evContext, evTimerFunc, void *, struct timespec,
178 		    struct timespec, evTimerID *));
179 int evClearTimer __P((evContext, evTimerID));
180 int evConfigTimer __P((evContext, evTimerID, const char *param,
181 		      int value));
182 int evResetTimer __P((evContext, evTimerID, evTimerFunc, void *,
183 		      struct timespec, struct timespec));
184 int evSetIdleTimer __P((evContext, evTimerFunc, void *, struct timespec,
185 			evTimerID *));
186 int evClearIdleTimer __P((evContext, evTimerID));
187 int evResetIdleTimer __P((evContext, evTimerID, evTimerFunc, void *,
188 			  struct timespec));
189 int evTouchIdleTimer __P((evContext, evTimerID));
190 
191 /* ev_waits.c */
192 #define evWaitFor	__evWaitFor
193 #define evDo		__evDo
194 #define evUnwait	__evUnwait
195 #define evDefer		__evDefer
196 
197 int evWaitFor __P((evContext, const void *, evWaitFunc, void *, evWaitID *));
198 int evDo __P((evContext, const void *));
199 int evUnwait __P((evContext, evWaitID));
200 int evDefer __P((evContext, evWaitFunc, void *));
201 
202 #ifdef __EVENTLIB_P_DEFINED
203 # undef __P
204 #endif
205 
206 #endif /*_EVENTLIB_H*/
207 
208 /*! \file */
209