#include <stdio.h>
    #include <stdlib.h>
    #include <sys/time.h>
    #include <signal.h>
    #include <event2/event.h>
    #include <event2/event_struct.h>

    struct self_tv{
    struct event* timeout;
    struct timeval tv;
    int order;
    };
    void sigroute(int fd, short event, void* arg) {
    struct self_tv* st = (struct self_tv*)arg;
    printf(“%d wake up\n”, st->order);
    st->tv.tv_sec = st->tv.tv_sec + 1;
    evtimer_add(st->timeout, &(st->tv));
    }

    int main()
    {
    struct event_base* eb;
    struct self_tv* st;
    int i=1;
    eb = event_base_new();
    for(i=0;i<=1000;i++) {
    st = (struct self_tv*)malloc(sizeof(struct self_tv));
    st->tv.tv_sec = 5;
    st->tv.tv_usec = 0;
    st->order = i;
    st->timeout = evtimer_new(eb, sigroute, st);
    evtimer_add(st->timeout, &st->tv);
    }
    event_base_dispatch(eb);
    return 0;
    }

     

    libevent的timer定时器在没有指定EV_PERSIST时是一次性事件。。。在回调里都需要再次evtimer_add一次。


相关文章:

  • 2021-09-29
  • 2021-11-30
  • 2021-06-28
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
猜你喜欢
  • 2021-06-13
  • 2022-12-23
  • 2021-06-01
  • 2022-12-23
  • 2021-07-15
  • 2021-12-26
相关资源
相似解决方案