rstatus_t core_loop(struct context *ctx) { int nsd, delta; int64_t now; now = nc_msec_now(); while (now >= ctx->next_tick) { core_tick(ctx); ctx->next_tick += NC_TICK_INTERVAL; } delta = (int)(ctx->next_tick - now); ASSERT(delta > 0); ctx->timeout = MIN(delta, ctx->timeout); nsd = event_wait(ctx->evb, ctx->timeout); if (nsd < 0) { return nsd; } core_timeout(ctx); stats_swap(ctx->stats); return NC_OK; }
rstatus_t core_loop(struct context *ctx) { int i, nsd, timeout; /* Note that we want call select() even if there are no * file events to process as long as we want to process time * events, in order to sleep until the next time event is ready * to fire. */ struct time_event *shortest = NULL; struct timeval tv, *tvp; shortest = event_search_nearest_timer(ctx); if (shortest) { long now_sec, now_ms; /* Calculate the time missing for the nearest * timer to fire. */ event_get_time(&now_sec, &now_ms); tvp = &tv; tvp->tv_sec = shortest->when_sec - now_sec; if (shortest->when_ms < now_ms) { tvp->tv_usec = ((shortest->when_ms+1000) - now_ms)*1000; tvp->tv_sec --; } else { tvp->tv_usec = (shortest->when_ms - now_ms)*1000; } if (tvp->tv_sec < 0) tvp->tv_sec = 0; if (tvp->tv_usec < 0) tvp->tv_usec = 0; timeout = tvp->tv_sec*1000 + tvp->tv_usec/1000; if (ctx->timeout < timeout) { timeout = ctx->timeout; } } else { timeout = ctx->timeout; } nsd = event_wait(ctx->ep, ctx->event, ctx->nevent, timeout); if (nsd < 0) { return nsd; } for (i = 0; i < nsd; i++) { struct epoll_event *ev = &ctx->event[i]; core_core(ctx, ev->data.ptr, ev->events); } event_process_timer(ctx); core_timeout(ctx); stats_swap(ctx->stats); return NC_OK; }
rstatus_t core_loop(struct context *ctx) { int nsd; nsd = event_wait(ctx->evb, ctx->timeout); if (nsd < 0) { return nsd; } core_timeout(ctx); stats_swap(ctx->stats); return NC_OK; }
rstatus_t core_loop(struct context *ctx) { int nsd; core_process_messages(); nsd = event_wait(ctx->evb, ctx->timeout); if (nsd < 0) { return nsd; } core_timeout(ctx); stats_swap(ctx->stats); return DN_OK; }
rstatus_t core_loop(struct context *ctx) { int i, nsd; nsd = event_wait(ctx->ep, ctx->event, ctx->nevent, ctx->timeout); if (nsd < 0) { return nsd; } for (i = 0; i < nsd; i++) { struct epoll_event *ev = &ctx->event[i]; core_core(ctx, ev->data.ptr, ev->events); } core_timeout(ctx); stats_swap(ctx->stats); return NC_OK; }