eventlib.h 6.78 KB
Newer Older
Mark Andrews's avatar
Mark Andrews committed
1
/*
Mark Andrews's avatar
Mark Andrews committed
2
 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
Mark Andrews's avatar
Mark Andrews committed
3 4 5 6 7 8
 * Copyright (c) 1995-1999 by Internet Software Consortium
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
Mark Andrews's avatar
Mark Andrews committed
9 10 11 12 13 14 15
 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Mark Andrews's avatar
Mark Andrews committed
16 17 18 19 20
 */

/* eventlib.h - exported interfaces for eventlib
 * vix 09sep95 [initial]
 *
21
 * $Id: eventlib.h,v 1.6 2008/01/23 02:00:56 marka Exp $
Mark Andrews's avatar
Mark Andrews committed
22 23 24 25 26 27 28 29 30 31
 */

#ifndef _EVENTLIB_H
#define _EVENTLIB_H

#include <sys/types.h>
#include <sys/uio.h>
#include <sys/time.h>
#include <stdio.h>

32 33
#include <isc/platform.h>

Mark Andrews's avatar
Mark Andrews committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#ifndef __P
# define __EVENTLIB_P_DEFINED
# ifdef __STDC__
#  define __P(x) x
# else
#  define __P(x) ()
# endif
#endif

/* In the absence of branded types... */
typedef struct { void *opaque; } evConnID;
typedef struct { void *opaque; } evFileID;
typedef struct { void *opaque; } evStreamID;
typedef struct { void *opaque; } evTimerID;
typedef struct { void *opaque; } evWaitID;
typedef struct { void *opaque; } evContext;
typedef struct { void *opaque; } evEvent;

#define	evInitID(id) ((id)->opaque = NULL)
#define	evTestID(id) ((id).opaque != NULL)

55 56 57 58 59 60 61
typedef void (*evConnFunc)__P((evContext, void *, int, const void *, int,
			       const void *, int));
typedef void (*evFileFunc)__P((evContext, void *, int, int));
typedef	void (*evStreamFunc)__P((evContext, void *, int, int));
typedef void (*evTimerFunc)__P((evContext, void *,
				struct timespec, struct timespec));
typedef	void (*evWaitFunc)__P((evContext, void *, const void *));
Mark Andrews's avatar
Mark Andrews committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

typedef	struct { unsigned char mask[256/8]; } evByteMask;
#define	EV_BYTEMASK_BYTE(b) ((b) / 8)
#define	EV_BYTEMASK_MASK(b) (1 << ((b) % 8))
#define	EV_BYTEMASK_SET(bm, b) \
	((bm).mask[EV_BYTEMASK_BYTE(b)] |= EV_BYTEMASK_MASK(b))
#define	EV_BYTEMASK_CLR(bm, b) \
	((bm).mask[EV_BYTEMASK_BYTE(b)] &= ~EV_BYTEMASK_MASK(b))
#define	EV_BYTEMASK_TST(bm, b) \
	((bm).mask[EV_BYTEMASK_BYTE(b)] & EV_BYTEMASK_MASK(b))

#define	EV_POLL		1
#define	EV_WAIT		2
#define	EV_NULL		4

#define	EV_READ		1
#define	EV_WRITE	2
#define	EV_EXCEPT	4

Mark Andrews's avatar
Mark Andrews committed
81 82
#define EV_WASNONBLOCKING 8	/* Internal library use. */

Mark Andrews's avatar
Mark Andrews committed
83 84 85 86 87 88 89 90 91
/* eventlib.c */
#define evCreate	__evCreate
#define evSetDebug	__evSetDebug
#define evDestroy	__evDestroy
#define evGetNext	__evGetNext
#define evDispatch	__evDispatch
#define evDrop		__evDrop
#define evMainLoop	__evMainLoop
#define evHighestFD	__evHighestFD
Mark Andrews's avatar
Mark Andrews committed
92 93
#define evGetOption	__evGetOption
#define evSetOption	__evSetOption
Mark Andrews's avatar
Mark Andrews committed
94

95 96 97 98 99 100 101 102
int  evCreate __P((evContext *));
void evSetDebug __P((evContext, int, FILE *));
int  evDestroy __P((evContext));
int  evGetNext __P((evContext, evEvent *, int));
int  evDispatch __P((evContext, evEvent));
void evDrop __P((evContext, evEvent));
int  evMainLoop __P((evContext));
int  evHighestFD __P((evContext));
Mark Andrews's avatar
Mark Andrews committed
103 104
int  evGetOption __P((evContext *, const char *, int *));
int  evSetOption __P((evContext *, const char *, int));
Mark Andrews's avatar
Mark Andrews committed
105 106 107 108 109 110 111 112 113

/* ev_connects.c */
#define evListen	__evListen
#define evConnect	__evConnect
#define evCancelConn	__evCancelConn
#define evHold		__evHold
#define evUnhold	__evUnhold
#define evTryAccept	__evTryAccept

114 115 116 117
int evListen __P((evContext, int, int, evConnFunc, void *, evConnID *));
int evConnect __P((evContext, int, const void *, int,
		   evConnFunc, void *, evConnID *));
int evCancelConn __P((evContext, evConnID));
Mark Andrews's avatar
Mark Andrews committed
118 119 120 121 122 123 124 125
int evHold __P((evContext, evConnID));
int evUnhold __P((evContext, evConnID));
int evTryAccept __P((evContext, evConnID, int *));

/* ev_files.c */
#define evSelectFD	__evSelectFD
#define evDeselectFD	__evDeselectFD

126 127
int evSelectFD __P((evContext, int, int, evFileFunc, void *, evFileID *));
int evDeselectFD __P((evContext, evFileID));
Mark Andrews's avatar
Mark Andrews committed
128 129 130 131 132 133 134 135 136

/* ev_streams.c */
#define evConsIovec	__evConsIovec
#define evWrite		__evWrite
#define evRead		__evRead
#define evTimeRW	__evTimeRW
#define evUntimeRW	__evUntimeRW
#define	evCancelRW	__evCancelRW

137 138 139 140 141 142 143 144
struct iovec evConsIovec __P((void *, size_t));
int evWrite __P((evContext, int, const struct iovec *, int,
		 evStreamFunc func, void *, evStreamID *));
int evRead __P((evContext, int, const struct iovec *, int,
		evStreamFunc func, void *, evStreamID *));
int evTimeRW __P((evContext, evStreamID, evTimerID timer));
int evUntimeRW __P((evContext, evStreamID));
int evCancelRW __P((evContext, evStreamID));
Mark Andrews's avatar
Mark Andrews committed
145 146 147 148 149 150 151 152 153 154

/* ev_timers.c */
#define evConsTime	__evConsTime
#define evAddTime	__evAddTime
#define evSubTime	__evSubTime
#define evCmpTime	__evCmpTime
#define	evTimeSpec	__evTimeSpec
#define	evTimeVal	__evTimeVal

#define evNowTime		__evNowTime
Mark Andrews's avatar
Mark Andrews committed
155
#define evUTCTime		__evUTCTime
Mark Andrews's avatar
Mark Andrews committed
156 157 158
#define evLastEventTime		__evLastEventTime
#define evSetTimer		__evSetTimer
#define evClearTimer		__evClearTimer
Mark Andrews's avatar
Mark Andrews committed
159
#define evConfigTimer		__evConfigTimer
Mark Andrews's avatar
Mark Andrews committed
160 161 162 163 164 165 166
#define evResetTimer		__evResetTimer
#define evSetIdleTimer		__evSetIdleTimer
#define evClearIdleTimer	__evClearIdleTimer
#define evResetIdleTimer	__evResetIdleTimer
#define evTouchIdleTimer	__evTouchIdleTimer

struct timespec evConsTime __P((time_t sec, long nsec));
167 168
struct timespec evAddTime __P((struct timespec, struct timespec));
struct timespec evSubTime __P((struct timespec, struct timespec));
Mark Andrews's avatar
Mark Andrews committed
169
struct timespec evNowTime __P((void));
Mark Andrews's avatar
Mark Andrews committed
170
struct timespec evUTCTime __P((void));
Mark Andrews's avatar
Mark Andrews committed
171 172 173
struct timespec evLastEventTime __P((evContext));
struct timespec evTimeSpec __P((struct timeval));
struct timeval evTimeVal __P((struct timespec));
174 175 176 177
int evCmpTime __P((struct timespec, struct timespec));
int evSetTimer __P((evContext, evTimerFunc, void *, struct timespec,
		    struct timespec, evTimerID *));
int evClearTimer __P((evContext, evTimerID));
Mark Andrews's avatar
Mark Andrews committed
178 179
int evConfigTimer __P((evContext, evTimerID, const char *param,
		      int value));
Mark Andrews's avatar
Mark Andrews committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
int evResetTimer __P((evContext, evTimerID, evTimerFunc, void *,
		      struct timespec, struct timespec));
int evSetIdleTimer __P((evContext, evTimerFunc, void *, struct timespec,
			evTimerID *));
int evClearIdleTimer __P((evContext, evTimerID));
int evResetIdleTimer __P((evContext, evTimerID, evTimerFunc, void *,
			  struct timespec));
int evTouchIdleTimer __P((evContext, evTimerID));

/* ev_waits.c */
#define evWaitFor	__evWaitFor
#define evDo		__evDo
#define evUnwait	__evUnwait
#define evDefer		__evDefer

195 196 197
int evWaitFor __P((evContext, const void *, evWaitFunc, void *, evWaitID *));
int evDo __P((evContext, const void *));
int evUnwait __P((evContext, evWaitID));
Mark Andrews's avatar
Mark Andrews committed
198 199 200 201 202 203 204
int evDefer __P((evContext, evWaitFunc, void *));

#ifdef __EVENTLIB_P_DEFINED
# undef __P
#endif

#endif /*_EVENTLIB_H*/
205 206

/*! \file */