diff --git a/src/ae.c b/src/ae.c index 689a27d..a4967fd 100644 --- a/src/ae.c +++ b/src/ae.c @@ -314,7 +314,7 @@ static int processTimeEvents(aeEventLoop *eventLoop) { long now_sec, now_ms; long long id; - /* Remove events scheduled for deletion. */ + /* 删除已经指定要删除的事件 */ if (te->id == AE_DELETED_EVENT_ID) { aeTimeEvent *next = te->next; /* If a reference exists for this timer event, @@ -354,9 +354,11 @@ static int processTimeEvents(aeEventLoop *eventLoop) { id = te->id; te->refcount++; + // 处理时间事件 retval = te->timeProc(eventLoop, id, te->clientData); te->refcount--; processed++; + // 重新设置时间事件到期时间 if (retval != AE_NOMORE) { aeAddMillisecondsToNow(retval,&te->when_sec,&te->when_ms); } else { diff --git a/src/ae.h b/src/ae.h index d1b7f34..fbfbce9 100644 --- a/src/ae.h +++ b/src/ae.h @@ -79,13 +79,13 @@ typedef struct aeFileEvent { /* Time event structure */ typedef struct aeTimeEvent { long long id; /* time event identifier. */ - long when_sec; /* seconds */ - long when_ms; /* milliseconds */ - aeTimeProc *timeProc; - aeEventFinalizerProc *finalizerProc; - void *clientData; - struct aeTimeEvent *prev; - struct aeTimeEvent *next; + long when_sec; /* 事件触发的秒数 */ + long when_ms; /* 事件触发的毫秒数 */ + aeTimeProc *timeProc;/* 指向时间事件的处理函数 */ + aeEventFinalizerProc *finalizerProc;/* 事件删除的时候会调用的函数 */ + void *clientData;/* 指向对应的客户端对象 */ + struct aeTimeEvent *prev;/* 指向上一个时间事件节点 */ + struct aeTimeEvent *next;/* 指向时下一个时间事件节点 */ int refcount; /* refcount to prevent timer events from being * freed in recursive time event calls. */ } aeTimeEvent; @@ -102,10 +102,10 @@ typedef struct aeEventLoop { int setsize; /* max number of file descriptors tracked */ long long timeEventNextId; time_t lastTime; /* Used to detect system clock skew */ - aeFileEvent *events; /* Registered events */ - aeFiredEvent *fired; /* Fired events */ + aeFileEvent *events; /* 注册过的事件 */ + aeFiredEvent *fired; /* 已经触发过的事件*/ aeTimeEvent *timeEventHead; - int stop; + int stop; /* 事件循环是否结束 */ void *apidata; /* This is used for polling API specific data */ aeBeforeSleepProc *beforesleep; aeBeforeSleepProc *aftersleep; diff --git a/src/server.c b/src/server.c index d484950..e6b634c 100644 --- a/src/server.c +++ b/src/server.c @@ -1961,7 +1961,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { } } - /* We need to do a few operations on clients asynchronously. */ + /* 清除无用客户端连接 */ clientsCron(); /* Handle background operations on Redis databases. */