Lines Matching refs:ctx

68 	evContext_p *ctx;  in evCreate()  local
74 OKNEW(ctx); in evCreate()
77 ctx->cur = NULL; in evCreate()
80 ctx->debug = 0; in evCreate()
81 ctx->output = NULL; in evCreate()
84 ctx->conns = NULL; in evCreate()
85 INIT_LIST(ctx->accepts); in evCreate()
88 ctx->files = NULL; in evCreate()
90 ctx->pollfds = NULL; in evCreate()
91 ctx->maxnfds = 0; in evCreate()
92 ctx->firstfd = 0; in evCreate()
93 emulMaskInit(ctx, rdLast, EV_READ, 1); in evCreate()
94 emulMaskInit(ctx, rdNext, EV_READ, 0); in evCreate()
95 emulMaskInit(ctx, wrLast, EV_WRITE, 1); in evCreate()
96 emulMaskInit(ctx, wrNext, EV_WRITE, 0); in evCreate()
97 emulMaskInit(ctx, exLast, EV_EXCEPT, 1); in evCreate()
98 emulMaskInit(ctx, exNext, EV_EXCEPT, 0); in evCreate()
99 emulMaskInit(ctx, nonblockBefore, EV_WASNONBLOCKING, 0); in evCreate()
101 FD_ZERO(&ctx->rdNext); in evCreate()
102 FD_ZERO(&ctx->wrNext); in evCreate()
103 FD_ZERO(&ctx->exNext); in evCreate()
104 FD_ZERO(&ctx->nonblockBefore); in evCreate()
105 ctx->fdMax = -1; in evCreate()
106 ctx->fdNext = NULL; in evCreate()
107 ctx->fdCount = 0; /*%< Invalidate {rd,wr,ex}Last. */ in evCreate()
109 ctx->highestFD = FD_SETSIZE - 1; in evCreate()
110 memset(ctx->fdTable, 0, sizeof ctx->fdTable); in evCreate()
112 ctx->highestFD = INT_MAX / sizeof(struct pollfd); in evCreate()
113 ctx->fdTable = NULL; in evCreate()
116 ctx->lastFdCount = 0; in evCreate()
120 ctx->streams = NULL; in evCreate()
121 ctx->strDone = NULL; in evCreate()
122 ctx->strLast = NULL; in evCreate()
125 ctx->lastEventTime = evNowTime(); in evCreate()
127 ctx->lastSelectTime = ctx->lastEventTime; in evCreate()
129 ctx->timers = evCreateTimers(ctx); in evCreate()
130 if (ctx->timers == NULL) in evCreate()
134 ctx->waitLists = NULL; in evCreate()
135 ctx->waitDone.first = ctx->waitDone.last = NULL; in evCreate()
136 ctx->waitDone.prev = ctx->waitDone.next = NULL; in evCreate()
138 opaqueCtx->opaque = ctx; in evCreate()
144 evContext_p *ctx = opaqueCtx.opaque; in evSetDebug() local
146 ctx->debug = level; in evSetDebug()
147 ctx->output = output; in evSetDebug()
152 evContext_p *ctx = opaqueCtx.opaque; in evDestroy() local
158 while (revs-- > 0 && ctx->conns != NULL) { in evDestroy()
161 id.opaque = ctx->conns; in evDestroy()
167 while (revs-- > 0 && ctx->streams != NULL) { in evDestroy()
170 id.opaque = ctx->streams; in evDestroy()
175 while (revs-- > 0 && ctx->files != NULL) { in evDestroy()
178 id.opaque = ctx->files; in evDestroy()
184 evDestroyTimers(ctx); in evDestroy()
187 for (this_wl = ctx->waitLists; in evDestroy()
199 for (this_wait = ctx->waitDone.first; in evDestroy()
206 FREE(ctx); in evDestroy()
212 evContext_p *ctx = opaqueCtx.opaque; in evGetNext() local
227 ctx->lastEventTime = evNowTime(); in evGetNext()
231 if (!EMPTY(ctx->accepts)) { in evGetNext()
234 new->u.accept.this = HEAD(ctx->accepts); in evGetNext()
235 UNLINK(ctx->accepts, HEAD(ctx->accepts), link); in evGetNext()
241 if (ctx->strDone != NULL) { in evGetNext()
244 new->u.stream.this = ctx->strDone; in evGetNext()
245 ctx->strDone = ctx->strDone->nextDone; in evGetNext()
246 if (ctx->strDone == NULL) in evGetNext()
247 ctx->strLast = NULL; in evGetNext()
253 if (ctx->waitDone.first != NULL) { in evGetNext()
256 new->u.wait.this = ctx->waitDone.first; in evGetNext()
257 ctx->waitDone.first = ctx->waitDone.first->next; in evGetNext()
258 if (ctx->waitDone.first == NULL) in evGetNext()
259 ctx->waitDone.last = NULL; in evGetNext()
265 if ((nextTimer = heap_element(ctx->timers, 1)) != NULL) { in evGetNext()
267 timerPast = (evCmpTime(nextTime, ctx->lastEventTime) <= 0); in evGetNext()
270 evPrintf(ctx, 9, "evGetNext: fdCount %d\n", ctx->fdCount); in evGetNext()
271 if (ctx->fdCount == 0) { in evGetNext()
277 if ((options & EV_WAIT) != 0 && !nextTimer && ctx->fdMax == -1) in evGetNext()
299 if (ctx->debug > 0) { in evGetNext()
300 interval = evSubTime(ctx->lastEventTime, in evGetNext()
301 ctx->lastSelectTime); in evGetNext()
303 evPrintf(ctx, 1, in evGetNext()
306 ctx->lastFdCount); in evGetNext()
312 ctx->rdLast = ctx->rdNext; in evGetNext()
313 ctx->wrLast = ctx->wrNext; in evGetNext()
314 ctx->exLast = ctx->exNext; in evGetNext()
325 t = evSubTime(nextTime, ctx->lastEventTime); in evGetNext()
329 x = pselect(ctx->fdMax+1, in evGetNext()
330 &ctx->rdLast, &ctx->wrLast, &ctx->exLast, in evGetNext()
335 evPrintf(ctx, 4, "select() returns %d (err: %s)\n", in evGetNext()
338 evPrintf(ctx, 4, "poll() returns %d (err: %s)\n", in evGetNext()
343 ctx->lastEventTime = evNowTime(); in evGetNext()
347 evCmpTime(ctx->lastEventTime, nextTime) < 0); in evGetNext()
349 ctx->lastSelectTime = ctx->lastEventTime; in evGetNext()
362 for (x = 0; x <= ctx->fdMax; x++) { in evGetNext()
365 if (FD_ISSET(x, &ctx->rdNext) == 0 && in evGetNext()
366 FD_ISSET(x, &ctx->wrNext) == 0 && in evGetNext()
367 FD_ISSET(x, &ctx->exNext) == 0) in evGetNext()
371 evPrintf(ctx, 1, "EBADF: %d\n", in evGetNext()
381 ctx->fdCount = x; in evGetNext()
383 ctx->lastFdCount = x; in evGetNext()
386 INSIST(nextTimer || ctx->fdCount); in evGetNext()
391 timerPast = (evCmpTime(nextTime, ctx->lastEventTime) <= 0); in evGetNext()
403 while (ctx->fdCount > 0) { in evGetNext()
407 if (ctx->fdNext == NULL) { in evGetNext()
425 ctx->fdCount = 0; in evGetNext()
428 ctx->fdNext = ctx->files; in evGetNext()
430 fid = ctx->fdNext; in evGetNext()
431 ctx->fdNext = fid->next; in evGetNext()
435 if (FD_ISSET(fd, &ctx->rdLast)) in evGetNext()
437 if (FD_ISSET(fd, &ctx->wrLast)) in evGetNext()
439 if (FD_ISSET(fd, &ctx->exLast)) in evGetNext()
444 FD_CLR(fd, &ctx->rdLast); in evGetNext()
445 ctx->fdCount--; in evGetNext()
448 FD_CLR(fd, &ctx->wrLast); in evGetNext()
449 ctx->fdCount--; in evGetNext()
452 FD_CLR(fd, &ctx->exLast); in evGetNext()
453 ctx->fdCount--; in evGetNext()
463 if (ctx->fdCount < 0) { in evGetNext()
468 evPrintf(ctx, 4, "fdCount < 0 (%d)\n", ctx->fdCount); in evGetNext()
469 ctx->fdCount = 0; in evGetNext()
478 evContext_p *ctx = opaqueCtx.opaque; in evDispatch() local
487 if (ctx->debug > 0) in evDispatch()
490 ctx->cur = ev; in evDispatch()
495 evPrintf(ctx, 5, in evDispatch()
512 evPrintf(ctx, 5, in evDispatch()
524 evPrintf(ctx, 5, in evDispatch()
537 evPrintf(ctx, 5, "Dispatch.Timer: func %p, uap %p\n", in evDispatch()
548 evPrintf(ctx, 5, in evDispatch()
569 if (ctx->debug > 0) { in evDispatch()
578 evPrintf(ctx, 1, in evDispatch()
584 ctx->cur = NULL; in evDispatch()
591 evContext_p *ctx = opaqueCtx.opaque; in evDrop() local
615 if (heap_element(ctx->timers, this->index) != this) { in evDrop()
616 evPrintf(ctx, 5, "Dispatch.Timer: timer rm'd?\n"); in evDrop()
633 ctx->lastEventTime, in evDrop()
667 evContext_p *ctx = opaqueCtx.opaque; in evHighestFD() local
669 return (ctx->highestFD); in evHighestFD()
673 evPrintf(const evContext_p *ctx, int level, const char *fmt, ...) { in evPrintf() argument
677 if (ctx->output != NULL && ctx->debug >= level) { in evPrintf()
678 vfprintf(ctx->output, fmt, ap); in evPrintf()
679 fflush(ctx->output); in evPrintf()
745 evContext_p *ctx; in pselect() local
771 ctx = ((__evEmulMask *)rfds)->ctx; in pselect()
773 ctx = ((__evEmulMask *)wfds)->ctx; in pselect()
775 ctx = ((__evEmulMask *)efds)->ctx; in pselect()
777 ctx = NULL; in pselect()
778 if (ctx != NULL && ctx->fdMax != -1) { in pselect()
779 fds = &(ctx->pollfds[ctx->firstfd]); in pselect()
780 pnfds = ctx->fdMax - ctx->firstfd + 1; in pselect()
789 INSIST(ctx != NULL); in pselect()
790 for (e = 0, i = ctx->firstfd; i <= ctx->fdMax; i++) { in pselect()
791 if (ctx->pollfds[i].fd < 0) in pselect()
793 if (FD_ISSET(i, &ctx->rdLast)) in pselect()
795 if (FD_ISSET(i, &ctx->wrLast)) in pselect()
797 if (FD_ISSET(i, &ctx->exLast)) in pselect()
813 evPollfdRealloc(evContext_p *ctx, int pollfd_chunk_size, int fd) { in evPollfdRealloc() argument
818 if (fd < ctx->maxnfds) in evPollfdRealloc()
827 pollfds = realloc(ctx->pollfds, maxnfds * sizeof(*ctx->pollfds)); in evPollfdRealloc()
829 ctx->pollfds = pollfds; in evPollfdRealloc()
830 fdTable = realloc(ctx->fdTable, maxnfds * sizeof(*ctx->fdTable)); in evPollfdRealloc()
832 ctx->fdTable = fdTable; in evPollfdRealloc()
835 evPrintf(ctx, 2, "pollfd() realloc (%ld) failed\n", in evPollfdRealloc()
840 for (i = ctx->maxnfds; i < maxnfds; i++) { in evPollfdRealloc()
841 ctx->pollfds[i].fd = -1; in evPollfdRealloc()
842 ctx->pollfds[i].events = 0; in evPollfdRealloc()
843 ctx->fdTable[i] = 0; in evPollfdRealloc()
846 ctx->maxnfds = maxnfds; in evPollfdRealloc()
855 evContext_p *ctx = (evContext_p *)maskp->ctx; in __fd_eventfield() local
858 return (&(ctx->pollfds[fd].events)); in __fd_eventfield()
860 return (&(ctx->pollfds[fd].revents)); in __fd_eventfield()
889 evContext_p *ctx = maskp->ctx; in __fd_clr() local
892 if ((ctx->pollfds[fd].events & ~POLLHUP) == 0) { in __fd_clr()
893 ctx->pollfds[fd].fd = -1; in __fd_clr()
894 if (fd == ctx->fdMax) in __fd_clr()
895 while (ctx->fdMax > ctx->firstfd && in __fd_clr()
896 ctx->pollfds[ctx->fdMax].fd < 0) in __fd_clr()
897 ctx->fdMax--; in __fd_clr()
898 if (fd == ctx->firstfd) in __fd_clr()
899 while (ctx->firstfd <= ctx->fdMax && in __fd_clr()
900 ctx->pollfds[ctx->firstfd].fd < 0) in __fd_clr()
901 ctx->firstfd++; in __fd_clr()
905 if (ctx->firstfd > ctx->fdMax) { in __fd_clr()
906 ctx->fdMax = -1; in __fd_clr()
907 ctx->firstfd = 0; in __fd_clr()
920 evContext_p *ctx = maskp->ctx; in __fd_set() local
923 if ((ctx->pollfds[fd].events & ~POLLHUP) != 0) { in __fd_set()
924 ctx->pollfds[fd].fd = fd; in __fd_set()
925 if (fd < ctx->firstfd || ctx->fdMax == -1) in __fd_set()
926 ctx->firstfd = fd; in __fd_set()
927 if (fd > ctx->fdMax) in __fd_set()
928 ctx->fdMax = fd; in __fd_set()