ev.h
int ev_register_cron(ev_context *ctx,
                     void (*callback)(ev_context *, void *),
                     void *data,
                     long long s, long long ns) {
#ifdef __linux__
    struct itimerspec timer;
    memset(&timer, 0x00, sizeof(timer));
    timer.it_value.tv_sec = s;
    timer.it_value.tv_nsec = ns;
    timer.it_interval.tv_sec = s;
    timer.it_interval.tv_nsec = ns;

    int timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);

    if (timerfd_settime(timerfd, 0, &timer, NULL) < 0)
        return EV_ERR;

    // Add the timer to the event loop
    ev_add_monitored(ctx, timerfd, EV_TIMERFD|EV_READ, callback, data);
    return ev_api_watch_fd(ctx, timerfd);
#else
    struct kqueue_api *k_api = ctx->api;
    // milliseconds
    unsigned period = (s * 1000)  + (ns / 100);
    int fd = socket(AF_INET, SOCK_STREAM, 0);
    ev_add_monitored(ctx, fd, EV_TIMERFD|EV_READ, callback, data);
    struct kevent ke;
    EV_SET(&ke, fd, EVFILT_TIMER, EV_ADD | EV_ENABLE, 0, period, 0);
    if (kevent(k_api->fd, &ke, 1, NULL, 0, NULL) == -1)
        return EV_ERR;
    return EV_OK;
#endif // __linux__
}
/*
 * Register a periodically repeate callback and args to be passed to a running
 * loop, specifying, seconds and/or nanoseconds defining how often the callback
 * should be executed.
 */
Register a periodically repeate callback and args to be passed to a running
loop, specifying, seconds and/or nanoseconds defining how often the callback
should be executed.
Register a periodically repeate callback and args to be passed to a running loop specifying seconds and / or nanoseconds defining how often the callback should be executed .
int ev_register_cron(ev_context *ctx,
                     void (*callback)(ev_context *, void *),
                     void *data,
                     long long s, long long ns) {
#ifdef __linux__
    struct itimerspec timer;
    memset(&timer, 0x00, sizeof(timer));
    timer.it_value.tv_sec = s;
    timer.it_value.tv_nsec = ns;
    timer.it_interval.tv_sec = s;
    timer.it_interval.tv_nsec = ns;
    int timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
    if (timerfd_settime(timerfd, 0, &timer, NULL) < 0)
        return EV_ERR;
    ev_add_monitored(ctx, timerfd, EV_TIMERFD|EV_READ, callback, data);
    return ev_api_watch_fd(ctx, timerfd);
#else
    struct kqueue_api *k_api = ctx->api;
    unsigned period = (s * 1000)  + (ns / 100);
    int fd = socket(AF_INET, SOCK_STREAM, 0);
    ev_add_monitored(ctx, fd, EV_TIMERFD|EV_READ, callback, data);
    struct kevent ke;
    EV_SET(&ke, fd, EVFILT_TIMER, EV_ADD | EV_ENABLE, 0, period, 0);
    if (kevent(k_api->fd, &ke, 1, NULL, 0, NULL) == -1)
        return EV_ERR;
    return EV_OK;
#endif 
}
int ev_register_cron ( ev_context * ctx , void ( * callback ) ( ev_context * , void * ) , void * data , long long s , long long ns ) { #ifdef __linux__ struct itimerspec timer ; memset ( & timer , 0x00 , sizeof ( timer ) ) ; timer . it_value . tv_sec = s ; timer . it_value . tv_nsec = ns ; timer . it_interval . tv_sec = s ; timer . it_interval . tv_nsec = ns ; int timerfd = timerfd_create ( CLOCK_MONOTONIC , TFD_NONBLOCK | TFD_CLOEXEC ) ; if ( timerfd_settime ( timerfd , 0 , & timer , NULL ) < 0 ) return EV_ERR ; ev_add_monitored ( ctx , timerfd , EV_TIMERFD | EV_READ , callback , data ) ; return ev_api_watch_fd ( ctx , timerfd ) ; #else struct kqueue_api * k_api = ctx -> api ; unsigned period = ( s * 1000 ) + ( ns / 100 ) ; int fd = socket ( AF_INET , SOCK_STREAM , 0 ) ; ev_add_monitored ( ctx , fd , EV_TIMERFD | EV_READ , callback , data ) ; struct kevent ke ; EV_SET ( & ke , fd , EVFILT_TIMER , EV_ADD | EV_ENABLE , 0 , period , 0 ) ; if ( kevent ( k_api -> fd , & ke , 1 , NULL , 0 , NULL ) == -1 ) return EV_ERR ; return EV_OK ; #endif }
Register a periodically repeate callback and args to be passed to a running
 loop, specifying, seconds and/or nanoseconds defining how often the callback
 should be executed.
Register a periodically repeate callback and args to be passed to a running loop specifying seconds and / or nanoseconds defining how often the callback should be executed .
// Add the timer to the event loop // milliseconds // __linux__