zoukankan      html  css  js  c++  java
  • libevent::事件::定时器2

    #define evtimer_new(b, cb, arg)        event_new((b), -1, 0, (cb), (arg))
    复制代码
    #include <cstdio>
    #include <errno.h>
    #include <sys/types.h>
    #include <event.h>
    #include <event2/event.h>
    #include <event2/event_struct.h>
    #include <event2/event-config.h>
    #include <event2/util.h>
    
    void do_timeout(evutil_socket_t fd, short event, void *arg)
    {
        printf("do timeout (time: %ld)!
    ", time(NULL));
    }
    
    void create_timeout_event(struct event_base *base)
    {
        struct event *ev;
        struct timeval timeout;
      
    //将事件和event_base绑定
    ev = event_new(base, -1, EV_PERSIST, do_timeout, NULL); if (ev) { timeout.tv_sec = 5; timeout.tv_usec = 0; event_add(ev, &timeout); } } int main(int argc, char **argv) { struct event_base *base; base = event_base_new(); if (!base) { printf("Error: Create an event base error! "); return -1; } create_timeout_event(base); event_base_dispatch(base); return (0); }
    复制代码
  • 相关阅读:
    118/119. Pascal's Triangle/II
    160. Intersection of Two Linked Lists
    168. Excel Sheet Column Title
    167. Two Sum II
    172. Factorial Trailing Zeroes
    169. Majority Element
    189. Rotate Array
    202. Happy Number
    204. Count Primes
    MVC之Model元数据
  • 原文地址:https://www.cnblogs.com/osbreak/p/10280038.html
Copyright © 2011-2022 走看看