Lines Matching refs:ctx

64 	evContext_p *ctx;  in evCreate()  local
70 OKNEW(ctx); in evCreate()
73 ctx->cur = NULL; in evCreate()
76 ctx->debug = 0; in evCreate()
77 ctx->output = NULL; in evCreate()
80 ctx->conns = NULL; in evCreate()
81 INIT_LIST(ctx->accepts); in evCreate()
84 ctx->files = NULL; in evCreate()
86 ctx->pollfds = NULL; in evCreate()
87 ctx->maxnfds = 0; in evCreate()
88 ctx->firstfd = 0; in evCreate()
89 emulMaskInit(ctx, rdLast, EV_READ, 1); in evCreate()
90 emulMaskInit(ctx, rdNext, EV_READ, 0); in evCreate()
91 emulMaskInit(ctx, wrLast, EV_WRITE, 1); in evCreate()
92 emulMaskInit(ctx, wrNext, EV_WRITE, 0); in evCreate()
93 emulMaskInit(ctx, exLast, EV_EXCEPT, 1); in evCreate()
94 emulMaskInit(ctx, exNext, EV_EXCEPT, 0); in evCreate()
95 emulMaskInit(ctx, nonblockBefore, EV_WASNONBLOCKING, 0); in evCreate()
97 FD_ZERO(&ctx->rdNext); in evCreate()
98 FD_ZERO(&ctx->wrNext); in evCreate()
99 FD_ZERO(&ctx->exNext); in evCreate()
100 FD_ZERO(&ctx->nonblockBefore); in evCreate()
101 ctx->fdMax = -1; in evCreate()
102 ctx->fdNext = NULL; in evCreate()
103 ctx->fdCount = 0; /*%< Invalidate {rd,wr,ex}Last. */ in evCreate()
105 ctx->highestFD = FD_SETSIZE - 1; in evCreate()
106 memset(ctx->fdTable, 0, sizeof ctx->fdTable); in evCreate()
108 ctx->highestFD = INT_MAX / sizeof(struct pollfd); in evCreate()
109 ctx->fdTable = NULL; in evCreate()
112 ctx->lastFdCount = 0; in evCreate()
116 ctx->streams = NULL; in evCreate()
117 ctx->strDone = NULL; in evCreate()
118 ctx->strLast = NULL; in evCreate()
121 ctx->lastEventTime = evNowTime(); in evCreate()
123 ctx->lastSelectTime = ctx->lastEventTime; in evCreate()
125 ctx->timers = evCreateTimers(ctx); in evCreate()
126 if (ctx->timers == NULL) in evCreate()
130 ctx->waitLists = NULL; in evCreate()
131 ctx->waitDone.first = ctx->waitDone.last = NULL; in evCreate()
132 ctx->waitDone.prev = ctx->waitDone.next = NULL; in evCreate()
134 opaqueCtx->opaque = ctx; in evCreate()
140 evContext_p *ctx = opaqueCtx.opaque; in evSetDebug() local
142 ctx->debug = level; in evSetDebug()
143 ctx->output = output; in evSetDebug()
148 evContext_p *ctx = opaqueCtx.opaque; in evDestroy() local
154 while (revs-- > 0 && ctx->conns != NULL) { in evDestroy()
157 id.opaque = ctx->conns; in evDestroy()
163 while (revs-- > 0 && ctx->streams != NULL) { in evDestroy()
166 id.opaque = ctx->streams; in evDestroy()
171 while (revs-- > 0 && ctx->files != NULL) { in evDestroy()
174 id.opaque = ctx->files; in evDestroy()
180 evDestroyTimers(ctx); in evDestroy()
183 for (this_wl = ctx->waitLists; in evDestroy()
195 for (this_wait = ctx->waitDone.first; in evDestroy()
202 FREE(ctx); in evDestroy()
208 evContext_p *ctx = opaqueCtx.opaque; in evGetNext() local
223 ctx->lastEventTime = evNowTime(); in evGetNext()
227 if (!EMPTY(ctx->accepts)) { in evGetNext()
230 new->u.accept.this = HEAD(ctx->accepts); in evGetNext()
231 UNLINK(ctx->accepts, HEAD(ctx->accepts), link); in evGetNext()
237 if (ctx->strDone != NULL) { in evGetNext()
240 new->u.stream.this = ctx->strDone; in evGetNext()
241 ctx->strDone = ctx->strDone->nextDone; in evGetNext()
242 if (ctx->strDone == NULL) in evGetNext()
243 ctx->strLast = NULL; in evGetNext()
249 if (ctx->waitDone.first != NULL) { in evGetNext()
252 new->u.wait.this = ctx->waitDone.first; in evGetNext()
253 ctx->waitDone.first = ctx->waitDone.first->next; in evGetNext()
254 if (ctx->waitDone.first == NULL) in evGetNext()
255 ctx->waitDone.last = NULL; in evGetNext()
261 if ((nextTimer = heap_element(ctx->timers, 1)) != NULL) { in evGetNext()
263 timerPast = (evCmpTime(nextTime, ctx->lastEventTime) <= 0); in evGetNext()
266 evPrintf(ctx, 9, "evGetNext: fdCount %d\n", ctx->fdCount); in evGetNext()
267 if (ctx->fdCount == 0) { in evGetNext()
273 if ((options & EV_WAIT) != 0 && !nextTimer && ctx->fdMax == -1) in evGetNext()
295 if (ctx->debug > 0) { in evGetNext()
296 interval = evSubTime(ctx->lastEventTime, in evGetNext()
297 ctx->lastSelectTime); in evGetNext()
299 evPrintf(ctx, 1, in evGetNext()
302 ctx->lastFdCount); in evGetNext()
308 ctx->rdLast = ctx->rdNext; in evGetNext()
309 ctx->wrLast = ctx->wrNext; in evGetNext()
310 ctx->exLast = ctx->exNext; in evGetNext()
321 t = evSubTime(nextTime, ctx->lastEventTime); in evGetNext()
325 x = pselect(ctx->fdMax+1, in evGetNext()
326 &ctx->rdLast, &ctx->wrLast, &ctx->exLast, in evGetNext()
331 evPrintf(ctx, 4, "select() returns %d (err: %s)\n", in evGetNext()
334 evPrintf(ctx, 4, "poll() returns %d (err: %s)\n", in evGetNext()
339 ctx->lastEventTime = evNowTime(); in evGetNext()
343 evCmpTime(ctx->lastEventTime, nextTime) < 0); in evGetNext()
345 ctx->lastSelectTime = ctx->lastEventTime; in evGetNext()
358 for (x = 0; x <= ctx->fdMax; x++) { in evGetNext()
361 if (FD_ISSET(x, &ctx->rdNext) == 0 && in evGetNext()
362 FD_ISSET(x, &ctx->wrNext) == 0 && in evGetNext()
363 FD_ISSET(x, &ctx->exNext) == 0) in evGetNext()
367 evPrintf(ctx, 1, "EBADF: %d\n", in evGetNext()
377 ctx->fdCount = x; in evGetNext()
379 ctx->lastFdCount = x; in evGetNext()
382 INSIST(nextTimer || ctx->fdCount); in evGetNext()
387 timerPast = (evCmpTime(nextTime, ctx->lastEventTime) <= 0); in evGetNext()
399 while (ctx->fdCount > 0) { in evGetNext()
403 if (ctx->fdNext == NULL) { in evGetNext()
421 ctx->fdCount = 0; in evGetNext()
424 ctx->fdNext = ctx->files; in evGetNext()
426 fid = ctx->fdNext; in evGetNext()
427 ctx->fdNext = fid->next; in evGetNext()
431 if (FD_ISSET(fd, &ctx->rdLast)) in evGetNext()
433 if (FD_ISSET(fd, &ctx->wrLast)) in evGetNext()
435 if (FD_ISSET(fd, &ctx->exLast)) in evGetNext()
440 FD_CLR(fd, &ctx->rdLast); in evGetNext()
441 ctx->fdCount--; in evGetNext()
444 FD_CLR(fd, &ctx->wrLast); in evGetNext()
445 ctx->fdCount--; in evGetNext()
448 FD_CLR(fd, &ctx->exLast); in evGetNext()
449 ctx->fdCount--; in evGetNext()
459 if (ctx->fdCount < 0) { in evGetNext()
464 evPrintf(ctx, 4, "fdCount < 0 (%d)\n", ctx->fdCount); in evGetNext()
465 ctx->fdCount = 0; in evGetNext()
474 evContext_p *ctx = opaqueCtx.opaque; in evDispatch() local
483 if (ctx->debug > 0) in evDispatch()
486 ctx->cur = ev; in evDispatch()
491 evPrintf(ctx, 5, in evDispatch()
508 evPrintf(ctx, 5, in evDispatch()
520 evPrintf(ctx, 5, in evDispatch()
533 evPrintf(ctx, 5, "Dispatch.Timer: func %p, uap %p\n", in evDispatch()
544 evPrintf(ctx, 5, in evDispatch()
565 if (ctx->debug > 0) { in evDispatch()
574 evPrintf(ctx, 1, in evDispatch()
580 ctx->cur = NULL; in evDispatch()
587 evContext_p *ctx = opaqueCtx.opaque; in evDrop() local
611 if (heap_element(ctx->timers, this->index) != this) { in evDrop()
612 evPrintf(ctx, 5, "Dispatch.Timer: timer rm'd?\n"); in evDrop()
629 ctx->lastEventTime, in evDrop()
663 evContext_p *ctx = opaqueCtx.opaque; in evHighestFD() local
665 return (ctx->highestFD); in evHighestFD()
669 evPrintf(const evContext_p *ctx, int level, const char *fmt, ...) { in evPrintf() argument
673 if (ctx->output != NULL && ctx->debug >= level) { in evPrintf()
674 vfprintf(ctx->output, fmt, ap); in evPrintf()
675 fflush(ctx->output); in evPrintf()
741 evContext_p *ctx; in pselect() local
769 ctx = ((__evEmulMask *)rfds)->ctx; in pselect()
771 ctx = ((__evEmulMask *)wfds)->ctx; in pselect()
773 ctx = ((__evEmulMask *)efds)->ctx; in pselect()
775 ctx = NULL; in pselect()
776 if (ctx != NULL && ctx->fdMax != -1) { in pselect()
777 fds = &(ctx->pollfds[ctx->firstfd]); in pselect()
778 pnfds = ctx->fdMax - ctx->firstfd + 1; in pselect()
787 INSIST(ctx != NULL); in pselect()
788 for (e = 0, i = ctx->firstfd; i <= ctx->fdMax; i++) { in pselect()
789 if (ctx->pollfds[i].fd < 0) in pselect()
791 if (FD_ISSET(i, &ctx->rdLast)) in pselect()
793 if (FD_ISSET(i, &ctx->wrLast)) in pselect()
795 if (FD_ISSET(i, &ctx->exLast)) in pselect()
811 evPollfdRealloc(evContext_p *ctx, int pollfd_chunk_size, int fd) { in evPollfdRealloc() argument
816 if (fd < ctx->maxnfds) in evPollfdRealloc()
825 pollfds = realloc(ctx->pollfds, maxnfds * sizeof(*ctx->pollfds)); in evPollfdRealloc()
827 ctx->pollfds = pollfds; in evPollfdRealloc()
828 fdTable = realloc(ctx->fdTable, maxnfds * sizeof(*ctx->fdTable)); in evPollfdRealloc()
830 ctx->fdTable = fdTable; in evPollfdRealloc()
833 evPrintf(ctx, 2, "pollfd() realloc (%ld) failed\n", in evPollfdRealloc()
838 for (i = ctx->maxnfds; i < maxnfds; i++) { in evPollfdRealloc()
839 ctx->pollfds[i].fd = -1; in evPollfdRealloc()
840 ctx->pollfds[i].events = 0; in evPollfdRealloc()
841 ctx->fdTable[i] = 0; in evPollfdRealloc()
844 ctx->maxnfds = maxnfds; in evPollfdRealloc()
853 evContext_p *ctx = (evContext_p *)maskp->ctx; in __fd_eventfield() local
856 return (&(ctx->pollfds[fd].events)); in __fd_eventfield()
858 return (&(ctx->pollfds[fd].revents)); in __fd_eventfield()
887 evContext_p *ctx = maskp->ctx; in __fd_clr() local
890 if ((ctx->pollfds[fd].events & ~POLLHUP) == 0) { in __fd_clr()
891 ctx->pollfds[fd].fd = -1; in __fd_clr()
892 if (fd == ctx->fdMax) in __fd_clr()
893 while (ctx->fdMax > ctx->firstfd && in __fd_clr()
894 ctx->pollfds[ctx->fdMax].fd < 0) in __fd_clr()
895 ctx->fdMax--; in __fd_clr()
896 if (fd == ctx->firstfd) in __fd_clr()
897 while (ctx->firstfd <= ctx->fdMax && in __fd_clr()
898 ctx->pollfds[ctx->firstfd].fd < 0) in __fd_clr()
899 ctx->firstfd++; in __fd_clr()
903 if (ctx->firstfd > ctx->fdMax) { in __fd_clr()
904 ctx->fdMax = -1; in __fd_clr()
905 ctx->firstfd = 0; in __fd_clr()
918 evContext_p *ctx = maskp->ctx; in __fd_set() local
921 if ((ctx->pollfds[fd].events & ~POLLHUP) != 0) { in __fd_set()
922 ctx->pollfds[fd].fd = fd; in __fd_set()
923 if (fd < ctx->firstfd || ctx->fdMax == -1) in __fd_set()
924 ctx->firstfd = fd; in __fd_set()
925 if (fd > ctx->fdMax) in __fd_set()
926 ctx->fdMax = fd; in __fd_set()