Lines Matching refs:ctx

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