libuev
Macros | Functions
cron.c File Reference

At/Cron like timers. More...

#include <errno.h>
#include <string.h>
#include <sys/timerfd.h>
#include <unistd.h>
#include "uev.h"
Include dependency graph for cron.c:

Macros

#define TFD_TIMER_CANCEL_ON_SET   (1 << 1)
 
#define TFD_SETTIME_FLAGS   (TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET)
 

Functions

int uev_cron_init (uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, time_t when, time_t interval)
 Create and start an at/cron job watcher. More...
 
int uev_cron_set (uev_t *w, time_t when, time_t interval)
 Reset an at/cron job watcher. More...
 
int uev_cron_start (uev_t *w)
 Start a stopped at/cron job watcher. More...
 
int uev_cron_stop (uev_t *w)
 Stop and unregister an at/cron job watcher. More...
 

Detailed Description

At/Cron like timers.

Function Documentation

◆ uev_cron_init()

int uev_cron_init ( uev_ctx_t ctx,
uev_t w,
uev_cb_t cb,
void *  arg,
time_t  when,
time_t  interval 
)

Create and start an at/cron job watcher.

Parameters
ctxA valid libuEv context
wPointer to an uev_t watcher
cbCallback function for cron job
argOptional callback argument
whenFirst point in time to call cb
intervalFor an at job this is zero, for cron the offset interval

For at jobs set interval to zero and only use when. For cron jobs, set interval to the offset. E.g., if the job should run every five minutes set the tm_min of struct tm to five.

Use mktime() to create the time_t arguments. The special value zero may be used for when to denote 'now', where 'now' is when the event loop is started. You can also treat time_t simply as a signed integer. E.g., set interval to 3600 to create a cron job that runs every hour.

Returns
POSIX OK(0) or non-zero with errno set on error.

◆ uev_cron_set()

int uev_cron_set ( uev_t w,
time_t  when,
time_t  interval 
)

Reset an at/cron job watcher.

Parameters
wWatcher to reset
whenFirst point in time to call cb
intervalFor an at job this is zero, for cron the offset interval
Returns
POSIX OK(0) or non-zero with errno set on error.

◆ uev_cron_start()

int uev_cron_start ( uev_t w)

Start a stopped at/cron job watcher.

Parameters
wWatcher to start (again)
Returns
POSIX OK(0) or non-zero with errno set on error.

◆ uev_cron_stop()

int uev_cron_stop ( uev_t w)

Stop and unregister an at/cron job watcher.

Parameters
wWatcher to stop
Returns
POSIX OK(0) or non-zero with errno set on error.