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; }
void stats_aggregate_force(struct stats *st) { pthread_mutex_lock(&st->stats_mutex); st->aggregate = 1; stats_aggregate(st); st->updated = 1; stats_swap(st); stats_aggregate(st); stats_pool_reset(&st->shadow); stats_pool_reset(&st->current); pthread_mutex_unlock(&st->stats_mutex); }
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; }
static rstatus_t stats_send_rsp(struct stats *st) { rstatus_t status; ssize_t n; //int sd; //int fd; status = stats_make_rsp(st); if (status != NC_OK) { return status; } /* sd = accept(st->sd, NULL, NULL); if (sd < 0) { log_error("accept on m %d failed: %s", st->sd, strerror(errno)); return NC_ERROR; } log_debug(LOG_VERB, "send stats on sd %d %d bytes", sd, st->buf.len); n = nc_sendn(sd, st->buf.data, st->buf.len); if (n < 0) { log_error("send stats on sd %d failed: %s", sd, strerror(errno)); close(sd); return NC_ERROR; } close(sd); */ nc_channel_msg_t message; memset(&message, 0, sizeof(nc_channel_msg_t)); message.command = NC_CMD_GET_STATS; message.len = st->buf.len; nc_write_channel(nc_worker_channel, &message, sizeof(nc_channel_msg_t)); n = nc_sendn(nc_worker_channel, st->buf.data, st->buf.len); if (n < 0) { log_error("nc_sendn %d failed: %s", nc_worker_channel, strerror(errno)); return NC_ERROR; } stats_swap(st); /* int fd = get_logger_fd(); if (fd < 0) { return; } n = nc_write(fd, st->buf.data, st->buf.len); if (n < 0) { log_error("nc_write %d failed: %s", fd, strerror(errno)); return NC_ERROR; } */ return NC_OK; }