/*!
 * \brief Teste le fonctionnement de l'assesseur qui permet d'accéder au temps
 */
void event_set_get_time_test ()
{
	TEST_TITLE ("event_set_get_time_test");
	PtrEvent event = NULL;
	event_create (&event);
	int time = event_get_time (event);
	TEST (time == 0);
	
	event_set_time (event, 15);
	
	time = event_get_time (event);
	TEST (time == 15);
	
	event -> Destroy (&event);
}
예제 #2
0
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;
}