redis的event处理过程基本流程
来源:互联网 发布:html页面嵌入php代码 编辑:程序博客网 时间:2024/05/17 21:45
这次分析aemain函数主要执行过程,会忽略部分细节处理;
void aeMain(aeEventLoop *eventLoop) { eventLoop->stop = 0; while (!eventLoop->stop) { if (eventLoop->beforesleep != NULL) eventLoop->beforesleep(eventLoop); aeProcessEvents(eventLoop, AE_ALL_EVENTS); }}这里主要是一个while循环,主要执行函数是eventLoop->beforesleep和aeProcessEvents,本次主要分析aeProcessEvents;关于aeProcessEvents有机会再分析;
int aeProcessEvents(aeEventLoop *eventLoop, int flags){ int processed = 0, numevents; /* Nothing to do? return ASAP */ if (!(flags & AE_TIME_EVENTS) && !(flags & AE_FILE_EVENTS)) return 0; /* Note that we want call select() even if there are no * file events to process as long as we want to process time * events, in order to sleep until the next time event is ready * to fire. */ if (eventLoop->maxfd != -1 || ((flags & AE_TIME_EVENTS) && !(flags & AE_DONT_WAIT))) { int j; aeTimeEvent *shortest = NULL; struct timeval tv, *tvp; if (flags & AE_TIME_EVENTS && !(flags & AE_DONT_WAIT)) shortest = aeSearchNearestTimer(eventLoop); if (shortest) { long now_sec, now_ms; aeGetTime(&now_sec, &now_ms); tvp = &tv; /* How many milliseconds we need to wait for the next * time event to fire? */ long long ms = (shortest->when_sec - now_sec)*1000 + shortest->when_ms - now_ms; if (ms > 0) { tvp->tv_sec = ms/1000; tvp->tv_usec = (ms % 1000)*1000; } else { tvp->tv_sec = 0; tvp->tv_usec = 0; } } else { /* If we have to check for events but need to return * ASAP because of AE_DONT_WAIT we need to set the timeout * to zero */ if (flags & AE_DONT_WAIT) { tv.tv_sec = tv.tv_usec = 0; tvp = &tv; } else { /* Otherwise we can block */ tvp = NULL; /* wait forever */ } } numevents = aeApiPoll(eventLoop, tvp); for (j = 0; j < numevents; j++) { aeFileEvent *fe = &eventLoop->events[eventLoop->fired[j].fd]; int mask = eventLoop->fired[j].mask; int fd = eventLoop->fired[j].fd; int rfired = 0; /* note the fe->mask & mask & ... code: maybe an already processed * event removed an element that fired and we still didn't * processed, so we check if the event is still valid. */ if (fe->mask & mask & AE_READABLE) { rfired = 1; fe->rfileProc(eventLoop,fd,fe->clientData,mask); } if (fe->mask & mask & AE_WRITABLE) { if (!rfired || fe->wfileProc != fe->rfileProc) fe->wfileProc(eventLoop,fd,fe->clientData,mask); } processed++; } } /* Check time events */ if (flags & AE_TIME_EVENTS) processed += processTimeEvents(eventLoop); return processed; /* return the number of processed file/time events */}本函数最主要部分是aeApiPoll,在它之前的部分是这个函数第二个参数tvp的赋值过程,目的是epoll等待的时间不超过下次time事件的时间;
之后是获取的事件执行对应的读写执行过程;
最后是timeevent的处理;
阅读全文
0 0
- redis的event处理过程基本流程
- opennms 的event的处理流程
- JPivot的基本处理流程
- Servlet处理的基本流程
- servlet处理的基本流程
- opencl处理的基本流程
- Qt中的Event处理流程
- redis网络事件的特殊处理——stale event
- 异常处理的基本过程
- 异常处理的基本过程
- redis 对基本数据类型的处理接口
- GPU图像处理的基本流程
- 腾讯信鸽推送基本流程和数据的处理流程
- SAP 基本处理流程
- memcached基本处理流程
- Libevent源码分析-event处理流程
- Redis文件事件处理用到的基本数据结构视图
- GL基本账务处理流程
- ios项目的托管
- Coins(多重背包)
- OpenCV学习之椭圆曲线拟合
- java基础总结 第一天
- 高德地图实现多点标注marker和动态信息窗体
- redis的event处理过程基本流程
- 怎么实现多个jar包一起依赖
- Java面向对象简单总结(二)
- 百练2765八进制小数题解
- LeetCode Graph:M210. Course Schedule II
- 第3节 毛中特(一)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- 计算机网络面试题
- OpenCV学习之由点集序列或者数组创建凸外形