首页 > 其他 > 详细

事件tou

时间:2014-07-17 22:37:33      阅读:416      评论:0      收藏:0      [点我收藏+]
#define EV_TIMER_RESOLUTION 1    /* 1 msec */

#define EV_READ_EVENT EPOLLIN
#define EV_WRITE_EVENT EPOLLOUT

struct ev_event;
struct ev_timer;

typedef void *ev_user_ptr;
typedef void (*ev_event_callback_t) (struct ev_event * event);

typedef void (*ev_timer_callback_t) (struct ev_timer * timer);

/* embed this to user data struct */
typedef struct ev_event {

    int fd;

    int events;

    ev_event_callback_t callback;

} ev_event_t;

typedef struct ev_timer {

    uint64_t msec;

    uint64_t abs_msec;

    ev_timer_callback_t callback;

    ev_user_ptr data;

    list_node_t list;
} ev_timer_t;

typedef struct ev_context {

    int efd;

    volatile int stopped;

    list_head_t timer_list;    /* timer! */

    int max_events;
    struct epoll_event events[0];
} ev_context_t;

ev_context_t *ev_create_context(int max_events);
void ev_destory_context(ev_context_t * c);

int ev_run(ev_context_t * c);

int ev_register_event(ev_context_t * c, ev_event_t * event);

void ev_unregister_event(ev_context_t * c, ev_event_t * event);

void ev_init_timer(ev_timer_t * timer, uint64_t msec,
           ev_timer_callback_t callback);

/* must called in same thread as ev_run  */
void ev_start_timer(ev_context_t * c, ev_timer_t * timer);

/* must called in same thread as ev_run  */
void ev_cancel_timer(ev_context_t * c, ev_timer_t * timer);

事件tou,布布扣,bubuko.com

事件tou

原文:http://www.cnblogs.com/unixshell/p/3851618.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!