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