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.3 2008/01/23 02:12:01 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 #include <isc/platform.h> 33 34 #ifndef __P 35 # define __EVENTLIB_P_DEFINED 36 # ifdef __STDC__ 37 # define __P(x) x 38 # else 39 # define __P(x) () 40 # endif 41 #endif 42 43 /* In the absence of branded types... */ 44 typedef struct { void *opaque; } evConnID; 45 typedef struct { void *opaque; } evFileID; 46 typedef struct { void *opaque; } evStreamID; 47 typedef struct { void *opaque; } evTimerID; 48 typedef struct { void *opaque; } evWaitID; 49 typedef struct { void *opaque; } evContext; 50 typedef struct { void *opaque; } evEvent; 51 52 #define evInitID(id) ((id)->opaque = NULL) 53 #define evTestID(id) ((id).opaque != NULL) 54 55 typedef void (*evConnFunc)__P((evContext, void *, int, const void *, int, 56 const void *, int)); 57 typedef void (*evFileFunc)__P((evContext, void *, int, int)); 58 typedef void (*evStreamFunc)__P((evContext, void *, int, int)); 59 typedef void (*evTimerFunc)__P((evContext, void *, 60 struct timespec, struct timespec)); 61 typedef void (*evWaitFunc)__P((evContext, void *, const void *)); 62 63 typedef struct { unsigned char mask[256/8]; } evByteMask; 64 #define EV_BYTEMASK_BYTE(b) ((b) / 8) 65 #define EV_BYTEMASK_MASK(b) (1 << ((b) % 8)) 66 #define EV_BYTEMASK_SET(bm, b) \ 67 ((bm).mask[EV_BYTEMASK_BYTE(b)] |= EV_BYTEMASK_MASK(b)) 68 #define EV_BYTEMASK_CLR(bm, b) \ 69 ((bm).mask[EV_BYTEMASK_BYTE(b)] &= ~EV_BYTEMASK_MASK(b)) 70 #define EV_BYTEMASK_TST(bm, b) \ 71 ((bm).mask[EV_BYTEMASK_BYTE(b)] & EV_BYTEMASK_MASK(b)) 72 73 #define EV_POLL 1 74 #define EV_WAIT 2 75 #define EV_NULL 4 76 77 #define EV_READ 1 78 #define EV_WRITE 2 79 #define EV_EXCEPT 4 80 81 #define EV_WASNONBLOCKING 8 /* Internal library use. */ 82 83 /* eventlib.c */ 84 #define evCreate __evCreate 85 #define evSetDebug __evSetDebug 86 #define evDestroy __evDestroy 87 #define evGetNext __evGetNext 88 #define evDispatch __evDispatch 89 #define evDrop __evDrop 90 #define evMainLoop __evMainLoop 91 #define evHighestFD __evHighestFD 92 #define evGetOption __evGetOption 93 #define evSetOption __evSetOption 94 95 int evCreate __P((evContext *)); 96 void evSetDebug __P((evContext, int, FILE *)); 97 int evDestroy __P((evContext)); 98 int evGetNext __P((evContext, evEvent *, int)); 99 int evDispatch __P((evContext, evEvent)); 100 void evDrop __P((evContext, evEvent)); 101 int evMainLoop __P((evContext)); 102 int evHighestFD __P((evContext)); 103 int evGetOption __P((evContext *, const char *, int *)); 104 int evSetOption __P((evContext *, const char *, int)); 105 106 /* ev_connects.c */ 107 #define evListen __evListen 108 #define evConnect __evConnect 109 #define evCancelConn __evCancelConn 110 #define evHold __evHold 111 #define evUnhold __evUnhold 112 #define evTryAccept __evTryAccept 113 114 int evListen __P((evContext, int, int, evConnFunc, void *, evConnID *)); 115 int evConnect __P((evContext, int, const void *, int, 116 evConnFunc, void *, evConnID *)); 117 int evCancelConn __P((evContext, evConnID)); 118 int evHold __P((evContext, evConnID)); 119 int evUnhold __P((evContext, evConnID)); 120 int evTryAccept __P((evContext, evConnID, int *)); 121 122 /* ev_files.c */ 123 #define evSelectFD __evSelectFD 124 #define evDeselectFD __evDeselectFD 125 126 int evSelectFD __P((evContext, int, int, evFileFunc, void *, evFileID *)); 127 int evDeselectFD __P((evContext, evFileID)); 128 129 /* ev_streams.c */ 130 #define evConsIovec __evConsIovec 131 #define evWrite __evWrite 132 #define evRead __evRead 133 #define evTimeRW __evTimeRW 134 #define evUntimeRW __evUntimeRW 135 #define evCancelRW __evCancelRW 136 137 struct iovec evConsIovec __P((void *, size_t)); 138 int evWrite __P((evContext, int, const struct iovec *, int, 139 evStreamFunc func, void *, evStreamID *)); 140 int evRead __P((evContext, int, const struct iovec *, int, 141 evStreamFunc func, void *, evStreamID *)); 142 int evTimeRW __P((evContext, evStreamID, evTimerID timer)); 143 int evUntimeRW __P((evContext, evStreamID)); 144 int evCancelRW __P((evContext, evStreamID)); 145 146 /* ev_timers.c */ 147 #define evConsTime __evConsTime 148 #define evAddTime __evAddTime 149 #define evSubTime __evSubTime 150 #define evCmpTime __evCmpTime 151 #define evTimeSpec __evTimeSpec 152 #define evTimeVal __evTimeVal 153 154 #define evNowTime __evNowTime 155 #define evUTCTime __evUTCTime 156 #define evLastEventTime __evLastEventTime 157 #define evSetTimer __evSetTimer 158 #define evClearTimer __evClearTimer 159 #define evConfigTimer __evConfigTimer 160 #define evResetTimer __evResetTimer 161 #define evSetIdleTimer __evSetIdleTimer 162 #define evClearIdleTimer __evClearIdleTimer 163 #define evResetIdleTimer __evResetIdleTimer 164 #define evTouchIdleTimer __evTouchIdleTimer 165 166 struct timespec evConsTime __P((time_t sec, long nsec)); 167 struct timespec evAddTime __P((struct timespec, struct timespec)); 168 struct timespec evSubTime __P((struct timespec, struct timespec)); 169 struct timespec evNowTime __P((void)); 170 struct timespec evUTCTime __P((void)); 171 struct timespec evLastEventTime __P((evContext)); 172 struct timespec evTimeSpec __P((struct timeval)); 173 struct timeval evTimeVal __P((struct timespec)); 174 int evCmpTime __P((struct timespec, struct timespec)); 175 int evSetTimer __P((evContext, evTimerFunc, void *, struct timespec, 176 struct timespec, evTimerID *)); 177 int evClearTimer __P((evContext, evTimerID)); 178 int evConfigTimer __P((evContext, evTimerID, const char *param, 179 int value)); 180 int evResetTimer __P((evContext, evTimerID, evTimerFunc, void *, 181 struct timespec, struct timespec)); 182 int evSetIdleTimer __P((evContext, evTimerFunc, void *, struct timespec, 183 evTimerID *)); 184 int evClearIdleTimer __P((evContext, evTimerID)); 185 int evResetIdleTimer __P((evContext, evTimerID, evTimerFunc, void *, 186 struct timespec)); 187 int evTouchIdleTimer __P((evContext, evTimerID)); 188 189 /* ev_waits.c */ 190 #define evWaitFor __evWaitFor 191 #define evDo __evDo 192 #define evUnwait __evUnwait 193 #define evDefer __evDefer 194 195 int evWaitFor __P((evContext, const void *, evWaitFunc, void *, evWaitID *)); 196 int evDo __P((evContext, const void *)); 197 int evUnwait __P((evContext, evWaitID)); 198 int evDefer __P((evContext, evWaitFunc, void *)); 199 200 #ifdef __EVENTLIB_P_DEFINED 201 # undef __P 202 #endif 203 204 #endif /*_EVENTLIB_H*/ 205 206 /*! \file */ 207