![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
libevent源码分析
scnuxiaotao
这个作者很懒,什么都没留下…
展开
-
[libevent]事件流程大览
我 们可以从sample的文件夹里面找到以下文件代码:int called = 0;static voidsignal_cb(int fd, short event, void *arg){ struct event *signal = arg; printf("%s: got signal %d\n", __func__, EVENT_SIGNAL(signal));原创 2016-07-21 14:32:04 · 548 阅读 · 0 评论 -
[libevent]epoll_dispatch()
static intepoll_dispatch(struct event_base *base, void *arg, struct timeval *tv){ struct epollop *epollop = arg; struct epoll_event *events = epollop->events; struct evepoll *evep; int i, res, t原创 2016-07-21 16:37:26 · 463 阅读 · 0 评论 -
[libevent]event/event_base/epollop/evsignal_info分析
经过了一个月对libevent1.4.13源码的学习,并且自己仿照了,码了一个c++版的,现在分享一下自己对源码关于epoll的一些分析。 学习源码的过程并挺好玩的,给想学习的同学以下建议:1.用source insight来看代码,非常方便,各种跳转功能和高亮,多窗口。2.可以看看张亮的分析,没有说对源码全部一句一句分析,其实也没必要,他讲得比较全面,剩下的代码自己完全可以看懂,原创 2016-07-21 13:48:18 · 406 阅读 · 0 评论 -
[libevent]evsignal_process()
voidevsignal_process(struct event_base *base){ struct evsignal_info *sig = &base->sig; struct event *ev, *next_ev; sig_atomic_t ncalls; int i; base->sig.evsignal_caught = 0; for (i = 1; i <原创 2016-07-21 16:27:09 · 315 阅读 · 0 评论 -
[libevent]evsignal_handler()
static voidevsignal_handler(int sig){ int save_errno = errno; if (evsignal_base == NULL) { event_warn( "%s: received signal %d, but have no base configured", __func__, sig); return; }原创 2016-07-21 16:23:20 · 321 阅读 · 0 评论 -
[libevent]_evsignal_restore_handler()
int_evsignal_restore_handler(struct event_base *base, int evsignal){ int ret = 0; struct evsignal_info *sig = &base->sig;#ifdef HAVE_SIGACTION struct sigaction *sh;#else ev_sighandler_t *sh;#原创 2016-07-21 16:20:44 · 273 阅读 · 0 评论 -
[libevent]_evsignal_set_handler()
int_evsignal_set_handler(struct event_base *base, int evsignal, void (*handler)(int)){#ifdef HAVE_SIGACTION struct sigaction sa;#else ev_sighandler_t sh;#endif struct evsignal_info *si原创 2016-07-21 16:19:03 · 367 阅读 · 0 评论 -
[libevent]evsignal_add()
intevsignal_add(struct event *ev){ int evsignal; struct event_base *base = ev->ev_base; struct evsignal_info *sig = &ev->ev_base->sig; if (ev->ev_events & (EV_READ|EV_WRITE)) event_errx(1, "%原创 2016-07-21 16:16:06 · 815 阅读 · 0 评论 -
[libevent]evsignal_init()
intevsignal_init(struct event_base *base){ int i; /* * Our signal handler is going to write to one end of the socket * pair to wake up our event loop. The event loop then scans for * sign原创 2016-07-21 16:11:03 · 798 阅读 · 0 评论 -
[libevent]event_process_active()
static voidevent_process_active(struct event_base *base){ struct event *ev; struct event_list *activeq = NULL; int i; short ncalls; for (i = 0; i nactivequeues; ++i) {//获得就绪链表中有就绪事件并且高优先级的表头原创 2016-07-21 16:02:33 · 1081 阅读 · 0 评论 -
[libevent]timeout_process()
voidtimeout_process(struct event_base *base){ struct timeval now; struct event *ev; if (min_heap_empty(&base->timeheap)) return; gettime(base, &now); while ((ev = min_heap_top(&base->timeh原创 2016-07-21 15:58:49 · 481 阅读 · 0 评论 -
[libevent]gettime()
static intgettime(struct event_base *base, struct timeval *tp){ if (base->tv_cache.tv_sec) {//如果有时间缓存则将缓存赋值给tp *tp = base->tv_cache; return (0); }#if defined(HAVE_CLOCK_GETTIME) && defined(C原创 2016-07-21 15:56:33 · 693 阅读 · 0 评论 -
[libevent]timeout_next()
static inttimeout_next(struct event_base *base, struct timeval **tv_p){ struct timeval now; struct event *ev; struct timeval *tv = *tv_p; if ((ev = min_heap_top(&base->timeheap)) == NULL) {//如果原创 2016-07-21 15:54:40 · 497 阅读 · 0 评论 -
[libevent]event_base_loop()
intevent_base_loop(struct event_base *base, int flags){ const struct eventop *evsel = base->evsel;//选择了epoll机制(如果之前选择了epoll) void *evbase = base->evbase;//epoll.c的epollop对象 struct timeval tv; st原创 2016-07-21 15:29:49 · 2249 阅读 · 0 评论 -
[libevent]event_add()
intevent_add(struct event *ev, const struct timeval *tv){ struct event_base *base = ev->ev_base;//与event关联的event_base const struct eventop *evsel = base->evsel;//其实就是epoll机制(若之前选择了epoll) void *ev原创 2016-07-21 15:10:52 · 712 阅读 · 0 评论 -
[libevent]event_set()
voidevent_set(struct event *ev, int fd, short events, void (*callback)(int, short, void *), void *arg){ /* Take the current base - caller needs to set the real base later */ ev->ev_base = curre原创 2016-07-21 14:57:12 · 806 阅读 · 0 评论 -
[libevent]event_base_new()
struct event_base *event_base_new(void){ int i; struct event_base *base; //相当于一个reactor,声明后分配空间 if ((base = calloc(1, sizeof(struct event_base))) == NULL) event_err(1, "%s: calloc", __func__);原创 2016-07-21 14:50:33 · 4431 阅读 · 0 评论 -
[libevent]epoll_add()
static intepoll_add(void *arg, struct event *ev){ struct epollop *epollop = arg; struct epoll_event epev = {0, {0}}; struct evepoll *evep; int fd, op, events; if (ev->ev_events & EV_SIGNAL)//信原创 2016-07-21 16:48:46 · 447 阅读 · 0 评论