1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/android/eventlib_p.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,243 @@ 1.4 +/* $NetBSD: eventlib_p.h,v 1.1.1.1 2004/05/20 19:34:32 christos Exp $ */ 1.5 + 1.6 +/* 1.7 + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 1.8 + * Copyright (c) 1995-1999 by Internet Software Consortium 1.9 + * 1.10 + * Permission to use, copy, modify, and distribute this software for any 1.11 + * purpose with or without fee is hereby granted, provided that the above 1.12 + * copyright notice and this permission notice appear in all copies. 1.13 + * 1.14 + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 1.15 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1.16 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 1.17 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1.18 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1.19 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 1.20 + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1.21 + */ 1.22 + 1.23 +/* eventlib_p.h - private interfaces for eventlib 1.24 + * vix 09sep95 [initial] 1.25 + * 1.26 + * Id: eventlib_p.h,v 1.3.2.1.4.1 2004/03/09 08:33:43 marka Exp 1.27 + */ 1.28 + 1.29 +/* 1.30 + * This version of this file is derived from Android 2.3 "Gingerbread", 1.31 + * which contains uncredited changes by Android/Google developers. It has 1.32 + * been modified in 2011 for use in the Android build of Mozilla Firefox by 1.33 + * Mozilla contributors (including Michael Edwards <m.k.edwards@gmail.com>, 1.34 + * and Steve Workman <sjhworkman@gmail.com>). 1.35 + * These changes are offered under the same license as the original NetBSD 1.36 + * file, whose copyright and license are unchanged above. 1.37 + */ 1.38 + 1.39 +#ifndef _EVENTLIB_P_H 1.40 +#define _EVENTLIB_P_H 1.41 + 1.42 +#include <sys/param.h> 1.43 +#include <sys/types.h> 1.44 +#include <sys/socket.h> 1.45 +#include <netinet/in.h> 1.46 +#include <sys/un.h> 1.47 + 1.48 +#define EVENTLIB_DEBUG 1 1.49 + 1.50 +#include <errno.h> 1.51 +#include <fcntl.h> 1.52 +#include <stdio.h> 1.53 +#include <stdlib.h> 1.54 +#include <string.h> 1.55 + 1.56 +#include "heap.h" 1.57 +#include "list.h" 1.58 +#include "memcluster.h" 1.59 + 1.60 + 1.61 +#define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT) 1.62 +#define EV_ERR(e) return (errno = (e), -1) 1.63 +#define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL 1.64 + 1.65 + 1.66 +#if HAVE_MEM_GET_SET 1.67 +#define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \ 1.68 + FILL(p); \ 1.69 + else \ 1.70 + (void)NULL; 1.71 +#define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \ 1.72 + errno = ENOMEM; \ 1.73 + return (-1); \ 1.74 + } else \ 1.75 + FILL(p) 1.76 +#define FREE(p) memput((p), sizeof *(p)) 1.77 + 1.78 +#if EVENTLIB_DEBUG 1.79 +#define FILL(p) memset((p), 0xF5, sizeof *(p)) 1.80 +#else 1.81 +#define FILL(p) 1.82 +#endif 1.83 + 1.84 +#else 1.85 + 1.86 +#define NEW(p) p = malloc(sizeof *(p)); 1.87 +#define OKNEW(p) if (!((p) = malloc(sizeof *(p)))) { errno = ENOMEM; return (-1); } 1.88 +#define FREE(p) free(p) 1.89 +#define FILL(p) 1.90 + 1.91 +#endif 1.92 + 1.93 + 1.94 +typedef struct evConn { 1.95 + evConnFunc func; 1.96 + void * uap; 1.97 + int fd; 1.98 + int flags; 1.99 +#define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */ 1.100 +#define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */ 1.101 +#define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */ 1.102 + evFileID file; 1.103 + struct evConn * prev; 1.104 + struct evConn * next; 1.105 +} evConn; 1.106 + 1.107 +typedef struct evAccept { 1.108 + int fd; 1.109 + union { 1.110 + struct sockaddr sa; 1.111 + struct sockaddr_in in; 1.112 +#ifndef NO_SOCKADDR_UN 1.113 + struct sockaddr_un un; 1.114 +#endif 1.115 + } la; 1.116 + socklen_t lalen; 1.117 + union { 1.118 + struct sockaddr sa; 1.119 + struct sockaddr_in in; 1.120 +#ifndef NO_SOCKADDR_UN 1.121 + struct sockaddr_un un; 1.122 +#endif 1.123 + } ra; 1.124 + socklen_t ralen; 1.125 + int ioErrno; 1.126 + evConn * conn; 1.127 + LINK(struct evAccept) link; 1.128 +} evAccept; 1.129 + 1.130 +typedef struct evFile { 1.131 + evFileFunc func; 1.132 + void * uap; 1.133 + int fd; 1.134 + int eventmask; 1.135 + int preemptive; 1.136 + struct evFile * prev; 1.137 + struct evFile * next; 1.138 + struct evFile * fdprev; 1.139 + struct evFile * fdnext; 1.140 +} evFile; 1.141 + 1.142 +typedef struct evStream { 1.143 + evStreamFunc func; 1.144 + void * uap; 1.145 + evFileID file; 1.146 + evTimerID timer; 1.147 + int flags; 1.148 +#define EV_STR_TIMEROK 0x0001 /* IFF timer valid. */ 1.149 + int fd; 1.150 + struct iovec * iovOrig; 1.151 + int iovOrigCount; 1.152 + struct iovec * iovCur; 1.153 + int iovCurCount; 1.154 + int ioTotal; 1.155 + int ioDone; 1.156 + int ioErrno; 1.157 + struct evStream *prevDone, *nextDone; 1.158 + struct evStream *prev, *next; 1.159 +} evStream; 1.160 + 1.161 +typedef struct evTimer { 1.162 + evTimerFunc func; 1.163 + void * uap; 1.164 + struct timespec due, inter; 1.165 + int index; 1.166 + int mode; 1.167 +#define EV_TMR_RATE 1 1.168 +} evTimer; 1.169 + 1.170 +typedef struct evWait { 1.171 + evWaitFunc func; 1.172 + void * uap; 1.173 + const void * tag; 1.174 + struct evWait * next; 1.175 +} evWait; 1.176 + 1.177 +typedef struct evWaitList { 1.178 + evWait * first; 1.179 + evWait * last; 1.180 + struct evWaitList * prev; 1.181 + struct evWaitList * next; 1.182 +} evWaitList; 1.183 + 1.184 +typedef struct evEvent_p { 1.185 + enum { Accept, File, Stream, Timer, Wait, Free, Null } type; 1.186 + union { 1.187 + struct { evAccept *this; } accept; 1.188 + struct { evFile *this; int eventmask; } file; 1.189 + struct { evStream *this; } stream; 1.190 + struct { evTimer *this; } timer; 1.191 + struct { evWait *this; } wait; 1.192 + struct { struct evEvent_p *next; } free; 1.193 + struct { const void *placeholder; } null; 1.194 + } u; 1.195 +} evEvent_p; 1.196 + 1.197 +typedef struct { 1.198 + /* Global. */ 1.199 + const evEvent_p *cur; 1.200 + /* Debugging. */ 1.201 + int debug; 1.202 + FILE *output; 1.203 + /* Connections. */ 1.204 + evConn *conns; 1.205 + LIST(evAccept) accepts; 1.206 + /* Files. */ 1.207 + evFile *files, *fdNext; 1.208 + fd_set rdLast, rdNext; 1.209 + fd_set wrLast, wrNext; 1.210 + fd_set exLast, exNext; 1.211 + fd_set nonblockBefore; 1.212 + int fdMax, fdCount, highestFD; 1.213 + evFile *fdTable[FD_SETSIZE]; 1.214 +#ifdef EVENTLIB_TIME_CHECKS 1.215 + struct timespec lastSelectTime; 1.216 + int lastFdCount; 1.217 +#endif 1.218 + /* Streams. */ 1.219 + evStream *streams; 1.220 + evStream *strDone, *strLast; 1.221 + /* Timers. */ 1.222 + struct timespec lastEventTime; 1.223 + heap_context timers; 1.224 + /* Waits. */ 1.225 + evWaitList *waitLists; 1.226 + evWaitList waitDone; 1.227 +} evContext_p; 1.228 + 1.229 +/* eventlib.c */ 1.230 +#define evPrintf __evPrintf 1.231 +void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...); 1.232 + 1.233 +/* ev_timers.c */ 1.234 +#define evCreateTimers __evCreateTimers 1.235 +heap_context evCreateTimers(const evContext_p *); 1.236 +#define evDestroyTimers __evDestroyTimers 1.237 +void evDestroyTimers(const evContext_p *); 1.238 + 1.239 +/* ev_waits.c */ 1.240 +#define evFreeWait __evFreeWait 1.241 +evWait *evFreeWait(evContext_p *ctx, evWait *old); 1.242 + 1.243 +/* Global options */ 1.244 +int __evOptMonoTime; 1.245 + 1.246 +#endif /*_EVENTLIB_P_H*/