xref: /freebsd/lib/libc/include/isc/eventlib.h (revision 861249f5830e8658b61130e0ee7eaad2e93d0449)
165e96449SHajimu UMEMOTO /*
265e96449SHajimu UMEMOTO  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
365e96449SHajimu UMEMOTO  * Copyright (c) 1995-1999 by Internet Software Consortium
465e96449SHajimu UMEMOTO  *
565e96449SHajimu UMEMOTO  * Permission to use, copy, modify, and distribute this software for any
665e96449SHajimu UMEMOTO  * purpose with or without fee is hereby granted, provided that the above
765e96449SHajimu UMEMOTO  * copyright notice and this permission notice appear in all copies.
865e96449SHajimu UMEMOTO  *
965e96449SHajimu UMEMOTO  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
1065e96449SHajimu UMEMOTO  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1165e96449SHajimu UMEMOTO  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
1265e96449SHajimu UMEMOTO  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1365e96449SHajimu UMEMOTO  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1465e96449SHajimu UMEMOTO  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
1565e96449SHajimu UMEMOTO  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1665e96449SHajimu UMEMOTO  */
1765e96449SHajimu UMEMOTO 
1865e96449SHajimu UMEMOTO /* eventlib.h - exported interfaces for eventlib
1965e96449SHajimu UMEMOTO  * vix 09sep95 [initial]
2065e96449SHajimu UMEMOTO  *
21861249f5SHajimu UMEMOTO  * $Id: eventlib.h,v 1.3.18.2 2005/07/28 07:38:07 marka Exp $
2265e96449SHajimu UMEMOTO  */
2365e96449SHajimu UMEMOTO 
2465e96449SHajimu UMEMOTO #ifndef _EVENTLIB_H
2565e96449SHajimu UMEMOTO #define _EVENTLIB_H
2665e96449SHajimu UMEMOTO 
2765e96449SHajimu UMEMOTO #include <sys/types.h>
2865e96449SHajimu UMEMOTO #include <sys/uio.h>
2965e96449SHajimu UMEMOTO #include <sys/time.h>
3065e96449SHajimu UMEMOTO #include <stdio.h>
3165e96449SHajimu UMEMOTO 
3265e96449SHajimu UMEMOTO #ifndef __P
3365e96449SHajimu UMEMOTO # define __EVENTLIB_P_DEFINED
3465e96449SHajimu UMEMOTO # ifdef __STDC__
3565e96449SHajimu UMEMOTO #  define __P(x) x
3665e96449SHajimu UMEMOTO # else
3765e96449SHajimu UMEMOTO #  define __P(x) ()
3865e96449SHajimu UMEMOTO # endif
3965e96449SHajimu UMEMOTO #endif
4065e96449SHajimu UMEMOTO 
4165e96449SHajimu UMEMOTO /* In the absence of branded types... */
4265e96449SHajimu UMEMOTO typedef struct { void *opaque; } evConnID;
4365e96449SHajimu UMEMOTO typedef struct { void *opaque; } evFileID;
4465e96449SHajimu UMEMOTO typedef struct { void *opaque; } evStreamID;
4565e96449SHajimu UMEMOTO typedef struct { void *opaque; } evTimerID;
4665e96449SHajimu UMEMOTO typedef struct { void *opaque; } evWaitID;
4765e96449SHajimu UMEMOTO typedef struct { void *opaque; } evContext;
4865e96449SHajimu UMEMOTO typedef struct { void *opaque; } evEvent;
4965e96449SHajimu UMEMOTO 
5065e96449SHajimu UMEMOTO #define	evInitID(id) ((id)->opaque = NULL)
5165e96449SHajimu UMEMOTO #define	evTestID(id) ((id).opaque != NULL)
5265e96449SHajimu UMEMOTO 
5365e96449SHajimu UMEMOTO typedef void (*evConnFunc)__P((evContext, void *, int, const void *, int,
5465e96449SHajimu UMEMOTO 			       const void *, int));
5565e96449SHajimu UMEMOTO typedef void (*evFileFunc)__P((evContext, void *, int, int));
5665e96449SHajimu UMEMOTO typedef	void (*evStreamFunc)__P((evContext, void *, int, int));
5765e96449SHajimu UMEMOTO typedef void (*evTimerFunc)__P((evContext, void *,
5865e96449SHajimu UMEMOTO 				struct timespec, struct timespec));
5965e96449SHajimu UMEMOTO typedef	void (*evWaitFunc)__P((evContext, void *, const void *));
6065e96449SHajimu UMEMOTO 
6165e96449SHajimu UMEMOTO typedef	struct { unsigned char mask[256/8]; } evByteMask;
6265e96449SHajimu UMEMOTO #define	EV_BYTEMASK_BYTE(b) ((b) / 8)
6365e96449SHajimu UMEMOTO #define	EV_BYTEMASK_MASK(b) (1 << ((b) % 8))
6465e96449SHajimu UMEMOTO #define	EV_BYTEMASK_SET(bm, b) \
6565e96449SHajimu UMEMOTO 	((bm).mask[EV_BYTEMASK_BYTE(b)] |= EV_BYTEMASK_MASK(b))
6665e96449SHajimu UMEMOTO #define	EV_BYTEMASK_CLR(bm, b) \
6765e96449SHajimu UMEMOTO 	((bm).mask[EV_BYTEMASK_BYTE(b)] &= ~EV_BYTEMASK_MASK(b))
6865e96449SHajimu UMEMOTO #define	EV_BYTEMASK_TST(bm, b) \
6965e96449SHajimu UMEMOTO 	((bm).mask[EV_BYTEMASK_BYTE(b)] & EV_BYTEMASK_MASK(b))
7065e96449SHajimu UMEMOTO 
7165e96449SHajimu UMEMOTO #define	EV_POLL		1
7265e96449SHajimu UMEMOTO #define	EV_WAIT		2
7365e96449SHajimu UMEMOTO #define	EV_NULL		4
7465e96449SHajimu UMEMOTO 
7565e96449SHajimu UMEMOTO #define	EV_READ		1
7665e96449SHajimu UMEMOTO #define	EV_WRITE	2
7765e96449SHajimu UMEMOTO #define	EV_EXCEPT	4
7865e96449SHajimu UMEMOTO 
7965e96449SHajimu UMEMOTO #define EV_WASNONBLOCKING 8	/* Internal library use. */
8065e96449SHajimu UMEMOTO 
8165e96449SHajimu UMEMOTO /* eventlib.c */
8265e96449SHajimu UMEMOTO #define evCreate	__evCreate
8365e96449SHajimu UMEMOTO #define evSetDebug	__evSetDebug
8465e96449SHajimu UMEMOTO #define evDestroy	__evDestroy
8565e96449SHajimu UMEMOTO #define evGetNext	__evGetNext
8665e96449SHajimu UMEMOTO #define evDispatch	__evDispatch
8765e96449SHajimu UMEMOTO #define evDrop		__evDrop
8865e96449SHajimu UMEMOTO #define evMainLoop	__evMainLoop
8965e96449SHajimu UMEMOTO #define evHighestFD	__evHighestFD
9065e96449SHajimu UMEMOTO #define evGetOption	__evGetOption
9165e96449SHajimu UMEMOTO #define evSetOption	__evSetOption
9265e96449SHajimu UMEMOTO 
9365e96449SHajimu UMEMOTO int  evCreate __P((evContext *));
9465e96449SHajimu UMEMOTO void evSetDebug __P((evContext, int, FILE *));
9565e96449SHajimu UMEMOTO int  evDestroy __P((evContext));
9665e96449SHajimu UMEMOTO int  evGetNext __P((evContext, evEvent *, int));
9765e96449SHajimu UMEMOTO int  evDispatch __P((evContext, evEvent));
9865e96449SHajimu UMEMOTO void evDrop __P((evContext, evEvent));
9965e96449SHajimu UMEMOTO int  evMainLoop __P((evContext));
10065e96449SHajimu UMEMOTO int  evHighestFD __P((evContext));
10165e96449SHajimu UMEMOTO int  evGetOption __P((evContext *, const char *, int *));
10265e96449SHajimu UMEMOTO int  evSetOption __P((evContext *, const char *, int));
10365e96449SHajimu UMEMOTO 
10465e96449SHajimu UMEMOTO /* ev_connects.c */
10565e96449SHajimu UMEMOTO #define evListen	__evListen
10665e96449SHajimu UMEMOTO #define evConnect	__evConnect
10765e96449SHajimu UMEMOTO #define evCancelConn	__evCancelConn
10865e96449SHajimu UMEMOTO #define evHold		__evHold
10965e96449SHajimu UMEMOTO #define evUnhold	__evUnhold
11065e96449SHajimu UMEMOTO #define evTryAccept	__evTryAccept
11165e96449SHajimu UMEMOTO 
11265e96449SHajimu UMEMOTO int evListen __P((evContext, int, int, evConnFunc, void *, evConnID *));
11365e96449SHajimu UMEMOTO int evConnect __P((evContext, int, const void *, int,
11465e96449SHajimu UMEMOTO 		   evConnFunc, void *, evConnID *));
11565e96449SHajimu UMEMOTO int evCancelConn __P((evContext, evConnID));
11665e96449SHajimu UMEMOTO int evHold __P((evContext, evConnID));
11765e96449SHajimu UMEMOTO int evUnhold __P((evContext, evConnID));
11865e96449SHajimu UMEMOTO int evTryAccept __P((evContext, evConnID, int *));
11965e96449SHajimu UMEMOTO 
12065e96449SHajimu UMEMOTO /* ev_files.c */
12165e96449SHajimu UMEMOTO #define evSelectFD	__evSelectFD
12265e96449SHajimu UMEMOTO #define evDeselectFD	__evDeselectFD
12365e96449SHajimu UMEMOTO 
12465e96449SHajimu UMEMOTO int evSelectFD __P((evContext, int, int, evFileFunc, void *, evFileID *));
12565e96449SHajimu UMEMOTO int evDeselectFD __P((evContext, evFileID));
12665e96449SHajimu UMEMOTO 
12765e96449SHajimu UMEMOTO /* ev_streams.c */
12865e96449SHajimu UMEMOTO #define evConsIovec	__evConsIovec
12965e96449SHajimu UMEMOTO #define evWrite		__evWrite
13065e96449SHajimu UMEMOTO #define evRead		__evRead
13165e96449SHajimu UMEMOTO #define evTimeRW	__evTimeRW
13265e96449SHajimu UMEMOTO #define evUntimeRW	__evUntimeRW
13365e96449SHajimu UMEMOTO #define	evCancelRW	__evCancelRW
13465e96449SHajimu UMEMOTO 
13565e96449SHajimu UMEMOTO struct iovec evConsIovec __P((void *, size_t));
13665e96449SHajimu UMEMOTO int evWrite __P((evContext, int, const struct iovec *, int,
13765e96449SHajimu UMEMOTO 		 evStreamFunc func, void *, evStreamID *));
13865e96449SHajimu UMEMOTO int evRead __P((evContext, int, const struct iovec *, int,
13965e96449SHajimu UMEMOTO 		evStreamFunc func, void *, evStreamID *));
14065e96449SHajimu UMEMOTO int evTimeRW __P((evContext, evStreamID, evTimerID timer));
14165e96449SHajimu UMEMOTO int evUntimeRW __P((evContext, evStreamID));
14265e96449SHajimu UMEMOTO int evCancelRW __P((evContext, evStreamID));
14365e96449SHajimu UMEMOTO 
14465e96449SHajimu UMEMOTO /* ev_timers.c */
14565e96449SHajimu UMEMOTO #define evConsTime	__evConsTime
14665e96449SHajimu UMEMOTO #define evAddTime	__evAddTime
14765e96449SHajimu UMEMOTO #define evSubTime	__evSubTime
14865e96449SHajimu UMEMOTO #define evCmpTime	__evCmpTime
14965e96449SHajimu UMEMOTO #define	evTimeSpec	__evTimeSpec
15065e96449SHajimu UMEMOTO #define	evTimeVal	__evTimeVal
15165e96449SHajimu UMEMOTO 
15265e96449SHajimu UMEMOTO #define evNowTime		__evNowTime
15365e96449SHajimu UMEMOTO #define evUTCTime		__evUTCTime
15465e96449SHajimu UMEMOTO #define evLastEventTime		__evLastEventTime
15565e96449SHajimu UMEMOTO #define evSetTimer		__evSetTimer
15665e96449SHajimu UMEMOTO #define evClearTimer		__evClearTimer
15765e96449SHajimu UMEMOTO #define evConfigTimer		__evConfigTimer
15865e96449SHajimu UMEMOTO #define evResetTimer		__evResetTimer
15965e96449SHajimu UMEMOTO #define evSetIdleTimer		__evSetIdleTimer
16065e96449SHajimu UMEMOTO #define evClearIdleTimer	__evClearIdleTimer
16165e96449SHajimu UMEMOTO #define evResetIdleTimer	__evResetIdleTimer
16265e96449SHajimu UMEMOTO #define evTouchIdleTimer	__evTouchIdleTimer
16365e96449SHajimu UMEMOTO 
16465e96449SHajimu UMEMOTO struct timespec evConsTime __P((time_t sec, long nsec));
16565e96449SHajimu UMEMOTO struct timespec evAddTime __P((struct timespec, struct timespec));
16665e96449SHajimu UMEMOTO struct timespec evSubTime __P((struct timespec, struct timespec));
16765e96449SHajimu UMEMOTO struct timespec evNowTime __P((void));
16865e96449SHajimu UMEMOTO struct timespec evUTCTime __P((void));
16965e96449SHajimu UMEMOTO struct timespec evLastEventTime __P((evContext));
17065e96449SHajimu UMEMOTO struct timespec evTimeSpec __P((struct timeval));
17165e96449SHajimu UMEMOTO struct timeval evTimeVal __P((struct timespec));
17265e96449SHajimu UMEMOTO int evCmpTime __P((struct timespec, struct timespec));
17365e96449SHajimu UMEMOTO int evSetTimer __P((evContext, evTimerFunc, void *, struct timespec,
17465e96449SHajimu UMEMOTO 		    struct timespec, evTimerID *));
17565e96449SHajimu UMEMOTO int evClearTimer __P((evContext, evTimerID));
17665e96449SHajimu UMEMOTO int evConfigTimer __P((evContext, evTimerID, const char *param,
17765e96449SHajimu UMEMOTO 		      int value));
17865e96449SHajimu UMEMOTO int evResetTimer __P((evContext, evTimerID, evTimerFunc, void *,
17965e96449SHajimu UMEMOTO 		      struct timespec, struct timespec));
18065e96449SHajimu UMEMOTO int evSetIdleTimer __P((evContext, evTimerFunc, void *, struct timespec,
18165e96449SHajimu UMEMOTO 			evTimerID *));
18265e96449SHajimu UMEMOTO int evClearIdleTimer __P((evContext, evTimerID));
18365e96449SHajimu UMEMOTO int evResetIdleTimer __P((evContext, evTimerID, evTimerFunc, void *,
18465e96449SHajimu UMEMOTO 			  struct timespec));
18565e96449SHajimu UMEMOTO int evTouchIdleTimer __P((evContext, evTimerID));
18665e96449SHajimu UMEMOTO 
18765e96449SHajimu UMEMOTO /* ev_waits.c */
18865e96449SHajimu UMEMOTO #define evWaitFor	__evWaitFor
18965e96449SHajimu UMEMOTO #define evDo		__evDo
19065e96449SHajimu UMEMOTO #define evUnwait	__evUnwait
19165e96449SHajimu UMEMOTO #define evDefer		__evDefer
19265e96449SHajimu UMEMOTO 
19365e96449SHajimu UMEMOTO int evWaitFor __P((evContext, const void *, evWaitFunc, void *, evWaitID *));
19465e96449SHajimu UMEMOTO int evDo __P((evContext, const void *));
19565e96449SHajimu UMEMOTO int evUnwait __P((evContext, evWaitID));
19665e96449SHajimu UMEMOTO int evDefer __P((evContext, evWaitFunc, void *));
19765e96449SHajimu UMEMOTO 
19865e96449SHajimu UMEMOTO #ifdef __EVENTLIB_P_DEFINED
19965e96449SHajimu UMEMOTO # undef __P
20065e96449SHajimu UMEMOTO #endif
20165e96449SHajimu UMEMOTO 
20265e96449SHajimu UMEMOTO #endif /*_EVENTLIB_H*/
203861249f5SHajimu UMEMOTO 
204861249f5SHajimu UMEMOTO /*! \file */
205