mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 09:00:51 +00:00
ae.c: Fix delay until next timer event.
This fix was written by Anthony LaTorre. The old code mis-calculated the amount of time to wait till next event.
This commit is contained in:
parent
ace780c002
commit
b9feef9ae8
21
src/ae.c
21
src/ae.c
@ -368,19 +368,22 @@ int aeProcessEvents(aeEventLoop *eventLoop, int flags)
|
||||
if (shortest) {
|
||||
long now_sec, now_ms;
|
||||
|
||||
/* Calculate the time missing for the nearest
|
||||
* timer to fire. */
|
||||
aeGetTime(&now_sec, &now_ms);
|
||||
tvp = &tv;
|
||||
tvp->tv_sec = shortest->when_sec - now_sec;
|
||||
if (shortest->when_ms < now_ms) {
|
||||
tvp->tv_usec = ((shortest->when_ms+1000) - now_ms)*1000;
|
||||
tvp->tv_sec --;
|
||||
|
||||
/* 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_usec = (shortest->when_ms - now_ms)*1000;
|
||||
tvp->tv_sec = 0;
|
||||
tvp->tv_usec = 0;
|
||||
}
|
||||
if (tvp->tv_sec < 0) tvp->tv_sec = 0;
|
||||
if (tvp->tv_usec < 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user