other-licenses/android/eventlib_p.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* $NetBSD: eventlib_p.h,v 1.1.1.1 2004/05/20 19:34:32 christos Exp $ */
michael@0 2
michael@0 3 /*
michael@0 4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
michael@0 5 * Copyright (c) 1995-1999 by Internet Software Consortium
michael@0 6 *
michael@0 7 * Permission to use, copy, modify, and distribute this software for any
michael@0 8 * purpose with or without fee is hereby granted, provided that the above
michael@0 9 * copyright notice and this permission notice appear in all copies.
michael@0 10 *
michael@0 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
michael@0 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
michael@0 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
michael@0 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
michael@0 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
michael@0 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
michael@0 17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
michael@0 18 */
michael@0 19
michael@0 20 /* eventlib_p.h - private interfaces for eventlib
michael@0 21 * vix 09sep95 [initial]
michael@0 22 *
michael@0 23 * Id: eventlib_p.h,v 1.3.2.1.4.1 2004/03/09 08:33:43 marka Exp
michael@0 24 */
michael@0 25
michael@0 26 /*
michael@0 27 * This version of this file is derived from Android 2.3 "Gingerbread",
michael@0 28 * which contains uncredited changes by Android/Google developers. It has
michael@0 29 * been modified in 2011 for use in the Android build of Mozilla Firefox by
michael@0 30 * Mozilla contributors (including Michael Edwards <m.k.edwards@gmail.com>,
michael@0 31 * and Steve Workman <sjhworkman@gmail.com>).
michael@0 32 * These changes are offered under the same license as the original NetBSD
michael@0 33 * file, whose copyright and license are unchanged above.
michael@0 34 */
michael@0 35
michael@0 36 #ifndef _EVENTLIB_P_H
michael@0 37 #define _EVENTLIB_P_H
michael@0 38
michael@0 39 #include <sys/param.h>
michael@0 40 #include <sys/types.h>
michael@0 41 #include <sys/socket.h>
michael@0 42 #include <netinet/in.h>
michael@0 43 #include <sys/un.h>
michael@0 44
michael@0 45 #define EVENTLIB_DEBUG 1
michael@0 46
michael@0 47 #include <errno.h>
michael@0 48 #include <fcntl.h>
michael@0 49 #include <stdio.h>
michael@0 50 #include <stdlib.h>
michael@0 51 #include <string.h>
michael@0 52
michael@0 53 #include "heap.h"
michael@0 54 #include "list.h"
michael@0 55 #include "memcluster.h"
michael@0 56
michael@0 57
michael@0 58 #define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT)
michael@0 59 #define EV_ERR(e) return (errno = (e), -1)
michael@0 60 #define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL
michael@0 61
michael@0 62
michael@0 63 #if HAVE_MEM_GET_SET
michael@0 64 #define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \
michael@0 65 FILL(p); \
michael@0 66 else \
michael@0 67 (void)NULL;
michael@0 68 #define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \
michael@0 69 errno = ENOMEM; \
michael@0 70 return (-1); \
michael@0 71 } else \
michael@0 72 FILL(p)
michael@0 73 #define FREE(p) memput((p), sizeof *(p))
michael@0 74
michael@0 75 #if EVENTLIB_DEBUG
michael@0 76 #define FILL(p) memset((p), 0xF5, sizeof *(p))
michael@0 77 #else
michael@0 78 #define FILL(p)
michael@0 79 #endif
michael@0 80
michael@0 81 #else
michael@0 82
michael@0 83 #define NEW(p) p = malloc(sizeof *(p));
michael@0 84 #define OKNEW(p) if (!((p) = malloc(sizeof *(p)))) { errno = ENOMEM; return (-1); }
michael@0 85 #define FREE(p) free(p)
michael@0 86 #define FILL(p)
michael@0 87
michael@0 88 #endif
michael@0 89
michael@0 90
michael@0 91 typedef struct evConn {
michael@0 92 evConnFunc func;
michael@0 93 void * uap;
michael@0 94 int fd;
michael@0 95 int flags;
michael@0 96 #define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */
michael@0 97 #define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */
michael@0 98 #define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */
michael@0 99 evFileID file;
michael@0 100 struct evConn * prev;
michael@0 101 struct evConn * next;
michael@0 102 } evConn;
michael@0 103
michael@0 104 typedef struct evAccept {
michael@0 105 int fd;
michael@0 106 union {
michael@0 107 struct sockaddr sa;
michael@0 108 struct sockaddr_in in;
michael@0 109 #ifndef NO_SOCKADDR_UN
michael@0 110 struct sockaddr_un un;
michael@0 111 #endif
michael@0 112 } la;
michael@0 113 socklen_t lalen;
michael@0 114 union {
michael@0 115 struct sockaddr sa;
michael@0 116 struct sockaddr_in in;
michael@0 117 #ifndef NO_SOCKADDR_UN
michael@0 118 struct sockaddr_un un;
michael@0 119 #endif
michael@0 120 } ra;
michael@0 121 socklen_t ralen;
michael@0 122 int ioErrno;
michael@0 123 evConn * conn;
michael@0 124 LINK(struct evAccept) link;
michael@0 125 } evAccept;
michael@0 126
michael@0 127 typedef struct evFile {
michael@0 128 evFileFunc func;
michael@0 129 void * uap;
michael@0 130 int fd;
michael@0 131 int eventmask;
michael@0 132 int preemptive;
michael@0 133 struct evFile * prev;
michael@0 134 struct evFile * next;
michael@0 135 struct evFile * fdprev;
michael@0 136 struct evFile * fdnext;
michael@0 137 } evFile;
michael@0 138
michael@0 139 typedef struct evStream {
michael@0 140 evStreamFunc func;
michael@0 141 void * uap;
michael@0 142 evFileID file;
michael@0 143 evTimerID timer;
michael@0 144 int flags;
michael@0 145 #define EV_STR_TIMEROK 0x0001 /* IFF timer valid. */
michael@0 146 int fd;
michael@0 147 struct iovec * iovOrig;
michael@0 148 int iovOrigCount;
michael@0 149 struct iovec * iovCur;
michael@0 150 int iovCurCount;
michael@0 151 int ioTotal;
michael@0 152 int ioDone;
michael@0 153 int ioErrno;
michael@0 154 struct evStream *prevDone, *nextDone;
michael@0 155 struct evStream *prev, *next;
michael@0 156 } evStream;
michael@0 157
michael@0 158 typedef struct evTimer {
michael@0 159 evTimerFunc func;
michael@0 160 void * uap;
michael@0 161 struct timespec due, inter;
michael@0 162 int index;
michael@0 163 int mode;
michael@0 164 #define EV_TMR_RATE 1
michael@0 165 } evTimer;
michael@0 166
michael@0 167 typedef struct evWait {
michael@0 168 evWaitFunc func;
michael@0 169 void * uap;
michael@0 170 const void * tag;
michael@0 171 struct evWait * next;
michael@0 172 } evWait;
michael@0 173
michael@0 174 typedef struct evWaitList {
michael@0 175 evWait * first;
michael@0 176 evWait * last;
michael@0 177 struct evWaitList * prev;
michael@0 178 struct evWaitList * next;
michael@0 179 } evWaitList;
michael@0 180
michael@0 181 typedef struct evEvent_p {
michael@0 182 enum { Accept, File, Stream, Timer, Wait, Free, Null } type;
michael@0 183 union {
michael@0 184 struct { evAccept *this; } accept;
michael@0 185 struct { evFile *this; int eventmask; } file;
michael@0 186 struct { evStream *this; } stream;
michael@0 187 struct { evTimer *this; } timer;
michael@0 188 struct { evWait *this; } wait;
michael@0 189 struct { struct evEvent_p *next; } free;
michael@0 190 struct { const void *placeholder; } null;
michael@0 191 } u;
michael@0 192 } evEvent_p;
michael@0 193
michael@0 194 typedef struct {
michael@0 195 /* Global. */
michael@0 196 const evEvent_p *cur;
michael@0 197 /* Debugging. */
michael@0 198 int debug;
michael@0 199 FILE *output;
michael@0 200 /* Connections. */
michael@0 201 evConn *conns;
michael@0 202 LIST(evAccept) accepts;
michael@0 203 /* Files. */
michael@0 204 evFile *files, *fdNext;
michael@0 205 fd_set rdLast, rdNext;
michael@0 206 fd_set wrLast, wrNext;
michael@0 207 fd_set exLast, exNext;
michael@0 208 fd_set nonblockBefore;
michael@0 209 int fdMax, fdCount, highestFD;
michael@0 210 evFile *fdTable[FD_SETSIZE];
michael@0 211 #ifdef EVENTLIB_TIME_CHECKS
michael@0 212 struct timespec lastSelectTime;
michael@0 213 int lastFdCount;
michael@0 214 #endif
michael@0 215 /* Streams. */
michael@0 216 evStream *streams;
michael@0 217 evStream *strDone, *strLast;
michael@0 218 /* Timers. */
michael@0 219 struct timespec lastEventTime;
michael@0 220 heap_context timers;
michael@0 221 /* Waits. */
michael@0 222 evWaitList *waitLists;
michael@0 223 evWaitList waitDone;
michael@0 224 } evContext_p;
michael@0 225
michael@0 226 /* eventlib.c */
michael@0 227 #define evPrintf __evPrintf
michael@0 228 void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...);
michael@0 229
michael@0 230 /* ev_timers.c */
michael@0 231 #define evCreateTimers __evCreateTimers
michael@0 232 heap_context evCreateTimers(const evContext_p *);
michael@0 233 #define evDestroyTimers __evDestroyTimers
michael@0 234 void evDestroyTimers(const evContext_p *);
michael@0 235
michael@0 236 /* ev_waits.c */
michael@0 237 #define evFreeWait __evFreeWait
michael@0 238 evWait *evFreeWait(evContext_p *ctx, evWait *old);
michael@0 239
michael@0 240 /* Global options */
michael@0 241 int __evOptMonoTime;
michael@0 242
michael@0 243 #endif /*_EVENTLIB_P_H*/

mercurial