暗淡青春|Redis1.0源码阅读笔记一、总体流程( 三 )
retval = select(maxfd+1, if (retval > 0) {fe = eventLoop->fileEventHead;while(fe != NULL) {int fd = (int) fe->fd;if ((fe->maskif (fe->maskif (fe->maskif (fe->mask/** fileProce = readQueryFromClient, sendReplyToClient, sendBulkToSlave, acceptHandler*/fe->fileProc(eventLoop, fe->fd, fe->clientData, mask);processed++;/* After an event is processed our file event list* may no longer be the same, so what we do* is to clear the bit for this file descriptor and* restart again from the head. */fe = eventLoop->fileEventHead;FD_CLR(fd,// FD_CLR(fd_set *fdset);用于在文件描述符集合中删除一个文件描述符 。FD_CLR(fd,FD_CLR(fd,} else {fe = fe->next;}}}
处理完socket事件后 , 就是处理时间事件 。 同处理socket类似 , 遍历eventLoop中的链表timeEventHead , 依次调用每个节点的timeProc函数 。 timeEventHead的每个节点 , 类型是struct aeTimeEvent , 由函数long long aeCreateTimeEvent(aeEventLoop *eventLoop, long long milliseconds, aeTimeProc *proc, void *clientData, aeEventFinalizerProc *finalizerProc)创建 。搜索全局 , 只在函数initServer中 , 调用了该函数 , 创建aeTimeEvent:aeCreateTimeEvent(server.el, 1000, serverCron, NULL, NULL); 。
【暗淡青春|Redis1.0源码阅读笔记一、总体流程】/* Check time events */if (flagsmaxId = eventLoop->timeEventNextId-1;while(te) {long now_sec, now_ms;long long id;if (te->id > maxId) {te = te->next;continue;}aeGetTime(if (now_sec > te->when_sec ||(now_sec == te->when_secid = te->id;retval = te->timeProc(eventLoop, id, te->clientData);/* After an event is processed our time event list may* no longer be the same, so we restart from head.* Still we make sure to don't process events registered* by event handlers itself in order to don't loop forever.* To do so we saved the max ID we want to handle. */if (retval != AE_NOMORE) {aeAddMillisecondsToNow(retval,} else {aeDeleteTimeEvent(eventLoop, id);}te = eventLoop->timeEventHead;} else {te = te->next;}}}
推荐阅读
- 暗淡青春|苹果明天搞大事!新iPad、iPhone 12发布时间要来了
- Miss西里|邓伦水洗蓝牛仔搭配清爽简约 顺毛发型尽显青春气息
- 艾希大人|竹内结子拍摄杂志封面 柠檬黄上衣青春活力
- M体育地带|青春风暴!意媒排出米兰U23首发阵容
- 街拍|美女街拍:青春时尚小姐姐,黑色吊带搭配牛仔热裤,魅力十足!
- 阳婷的青春|将相和的主人翁廉颇、蔺相如最后结局如何?你真不一定知道!
- 粉笔教育带你走近90后扶贫基层,聆听“女承父志”的青春故事
- 街拍|街拍:光彩照人小姐姐,时尚的打扮,尽显青春魅力!
- 街拍|街拍:简单时尚的小姐姐,青春时尚,展现出曼妙身姿!
- 墨羽青春穿搭札记|同台比美都翻车!张靓颖暴露麒麟臂,吴昕显腿粗,喻言造型拖沓