设为首页 加入收藏

TOP

libevent中定时器的使用方法
2014-11-24 07:42:53 】 浏览:1456
Tags:libevent 定时器 使用方法
    #include 
  
   
    #include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         struct self_tv{ struct event* timeout; struct timeva l 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一次。 
       
      
     
    
   
  

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇libevent库的使用方法 下一篇LeetCode Simplify Path

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目