samedi 7 septembre 2019

How to make event created by libevent work only when the event is true in cpp?

I was able to use libevent to trigger a function every n seconds but is there a way to utilize or do something when events are not active? How can it be achieved?

void say_hello(int fd, short event, void *arg)
{
  printf("Hello\n");
}

int main(int argc, const char* argv[])
{
  struct event ev;
  struct timeval tv;

  int a = 3;

  tv.tv_sec = 1;
  tv.tv_usec = 0;

  event_init();

  event_set(&ev, 0, EV_PERSIST, say_hello, &a);
  evtimer_add(&ev, &tv);
  event_dispatch();
  printf("stuff") # what's the most sensible way to do this if event 
  return 0;       # not active?
}


Aucun commentaire:

Enregistrer un commentaire