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