michael@0: /* $NetBSD: eventlib_p.h,v 1.1.1.1 2004/05/20 19:34:32 christos Exp $ */ michael@0: michael@0: /* michael@0: * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") michael@0: * Copyright (c) 1995-1999 by Internet Software Consortium michael@0: * michael@0: * Permission to use, copy, modify, and distribute this software for any michael@0: * purpose with or without fee is hereby granted, provided that the above michael@0: * copyright notice and this permission notice appear in all copies. michael@0: * michael@0: * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES michael@0: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF michael@0: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR michael@0: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES michael@0: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN michael@0: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT michael@0: * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. michael@0: */ michael@0: michael@0: /* eventlib_p.h - private interfaces for eventlib michael@0: * vix 09sep95 [initial] michael@0: * michael@0: * Id: eventlib_p.h,v 1.3.2.1.4.1 2004/03/09 08:33:43 marka Exp michael@0: */ michael@0: michael@0: /* michael@0: * This version of this file is derived from Android 2.3 "Gingerbread", michael@0: * which contains uncredited changes by Android/Google developers. It has michael@0: * been modified in 2011 for use in the Android build of Mozilla Firefox by michael@0: * Mozilla contributors (including Michael Edwards , michael@0: * and Steve Workman ). michael@0: * These changes are offered under the same license as the original NetBSD michael@0: * file, whose copyright and license are unchanged above. michael@0: */ michael@0: michael@0: #ifndef _EVENTLIB_P_H michael@0: #define _EVENTLIB_P_H michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #define EVENTLIB_DEBUG 1 michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "heap.h" michael@0: #include "list.h" michael@0: #include "memcluster.h" michael@0: michael@0: michael@0: #define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT) michael@0: #define EV_ERR(e) return (errno = (e), -1) michael@0: #define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL michael@0: michael@0: michael@0: #if HAVE_MEM_GET_SET michael@0: #define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \ michael@0: FILL(p); \ michael@0: else \ michael@0: (void)NULL; michael@0: #define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \ michael@0: errno = ENOMEM; \ michael@0: return (-1); \ michael@0: } else \ michael@0: FILL(p) michael@0: #define FREE(p) memput((p), sizeof *(p)) michael@0: michael@0: #if EVENTLIB_DEBUG michael@0: #define FILL(p) memset((p), 0xF5, sizeof *(p)) michael@0: #else michael@0: #define FILL(p) michael@0: #endif michael@0: michael@0: #else michael@0: michael@0: #define NEW(p) p = malloc(sizeof *(p)); michael@0: #define OKNEW(p) if (!((p) = malloc(sizeof *(p)))) { errno = ENOMEM; return (-1); } michael@0: #define FREE(p) free(p) michael@0: #define FILL(p) michael@0: michael@0: #endif michael@0: michael@0: michael@0: typedef struct evConn { michael@0: evConnFunc func; michael@0: void * uap; michael@0: int fd; michael@0: int flags; michael@0: #define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */ michael@0: #define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */ michael@0: #define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */ michael@0: evFileID file; michael@0: struct evConn * prev; michael@0: struct evConn * next; michael@0: } evConn; michael@0: michael@0: typedef struct evAccept { michael@0: int fd; michael@0: union { michael@0: struct sockaddr sa; michael@0: struct sockaddr_in in; michael@0: #ifndef NO_SOCKADDR_UN michael@0: struct sockaddr_un un; michael@0: #endif michael@0: } la; michael@0: socklen_t lalen; michael@0: union { michael@0: struct sockaddr sa; michael@0: struct sockaddr_in in; michael@0: #ifndef NO_SOCKADDR_UN michael@0: struct sockaddr_un un; michael@0: #endif michael@0: } ra; michael@0: socklen_t ralen; michael@0: int ioErrno; michael@0: evConn * conn; michael@0: LINK(struct evAccept) link; michael@0: } evAccept; michael@0: michael@0: typedef struct evFile { michael@0: evFileFunc func; michael@0: void * uap; michael@0: int fd; michael@0: int eventmask; michael@0: int preemptive; michael@0: struct evFile * prev; michael@0: struct evFile * next; michael@0: struct evFile * fdprev; michael@0: struct evFile * fdnext; michael@0: } evFile; michael@0: michael@0: typedef struct evStream { michael@0: evStreamFunc func; michael@0: void * uap; michael@0: evFileID file; michael@0: evTimerID timer; michael@0: int flags; michael@0: #define EV_STR_TIMEROK 0x0001 /* IFF timer valid. */ michael@0: int fd; michael@0: struct iovec * iovOrig; michael@0: int iovOrigCount; michael@0: struct iovec * iovCur; michael@0: int iovCurCount; michael@0: int ioTotal; michael@0: int ioDone; michael@0: int ioErrno; michael@0: struct evStream *prevDone, *nextDone; michael@0: struct evStream *prev, *next; michael@0: } evStream; michael@0: michael@0: typedef struct evTimer { michael@0: evTimerFunc func; michael@0: void * uap; michael@0: struct timespec due, inter; michael@0: int index; michael@0: int mode; michael@0: #define EV_TMR_RATE 1 michael@0: } evTimer; michael@0: michael@0: typedef struct evWait { michael@0: evWaitFunc func; michael@0: void * uap; michael@0: const void * tag; michael@0: struct evWait * next; michael@0: } evWait; michael@0: michael@0: typedef struct evWaitList { michael@0: evWait * first; michael@0: evWait * last; michael@0: struct evWaitList * prev; michael@0: struct evWaitList * next; michael@0: } evWaitList; michael@0: michael@0: typedef struct evEvent_p { michael@0: enum { Accept, File, Stream, Timer, Wait, Free, Null } type; michael@0: union { michael@0: struct { evAccept *this; } accept; michael@0: struct { evFile *this; int eventmask; } file; michael@0: struct { evStream *this; } stream; michael@0: struct { evTimer *this; } timer; michael@0: struct { evWait *this; } wait; michael@0: struct { struct evEvent_p *next; } free; michael@0: struct { const void *placeholder; } null; michael@0: } u; michael@0: } evEvent_p; michael@0: michael@0: typedef struct { michael@0: /* Global. */ michael@0: const evEvent_p *cur; michael@0: /* Debugging. */ michael@0: int debug; michael@0: FILE *output; michael@0: /* Connections. */ michael@0: evConn *conns; michael@0: LIST(evAccept) accepts; michael@0: /* Files. */ michael@0: evFile *files, *fdNext; michael@0: fd_set rdLast, rdNext; michael@0: fd_set wrLast, wrNext; michael@0: fd_set exLast, exNext; michael@0: fd_set nonblockBefore; michael@0: int fdMax, fdCount, highestFD; michael@0: evFile *fdTable[FD_SETSIZE]; michael@0: #ifdef EVENTLIB_TIME_CHECKS michael@0: struct timespec lastSelectTime; michael@0: int lastFdCount; michael@0: #endif michael@0: /* Streams. */ michael@0: evStream *streams; michael@0: evStream *strDone, *strLast; michael@0: /* Timers. */ michael@0: struct timespec lastEventTime; michael@0: heap_context timers; michael@0: /* Waits. */ michael@0: evWaitList *waitLists; michael@0: evWaitList waitDone; michael@0: } evContext_p; michael@0: michael@0: /* eventlib.c */ michael@0: #define evPrintf __evPrintf michael@0: void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...); michael@0: michael@0: /* ev_timers.c */ michael@0: #define evCreateTimers __evCreateTimers michael@0: heap_context evCreateTimers(const evContext_p *); michael@0: #define evDestroyTimers __evDestroyTimers michael@0: void evDestroyTimers(const evContext_p *); michael@0: michael@0: /* ev_waits.c */ michael@0: #define evFreeWait __evFreeWait michael@0: evWait *evFreeWait(evContext_p *ctx, evWait *old); michael@0: michael@0: /* Global options */ michael@0: int __evOptMonoTime; michael@0: michael@0: #endif /*_EVENTLIB_P_H*/