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