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