I'm currently trying to use libevent to call a function every n minutes / an event trigger that would call the function and was suggested that libevent can be used. I could use it persistently call the function every n seconds but was unable to figure how to pass arguments to them.
#include <stdio.h>
#include <sys/time.h>
#include <event.h>
void say_hello(int fd, short event, void *arg)
{
printf("Hello\n");
// printf("%d", (int *)arg[0])
}
int main(int argc, const char* argv[])
{
struct event ev;
struct timeval tv;
tv.tv_sec = 3;
tv.tv_usec = 0;
event_init();
// event_set(&my_event, 0, EV_PERSIST, my_function, NULL);
event_set(&ev, 0, EV_PERSIST, say_hello, NULL);
// evtimer_set(&ev, say_hello, NULL);
evtimer_add(&ev, &tv);
event_dispatch();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire