Software /
code /
prosody
Comparison
net/server_epoll.lua @ 7624:23fb3a084956
net.server_epoll: Comments
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 22 Aug 2016 17:13:39 +0200 |
parent | 7623:a1c040a5754f |
child | 7625:6afafd6d4ef0 |
comparison
equal
deleted
inserted
replaced
7623:a1c040a5754f | 7624:23fb3a084956 |
---|---|
83 | 83 |
84 -- Iterate from the end and remove completed timers | 84 -- Iterate from the end and remove completed timers |
85 for i = #timers, 1, -1 do | 85 for i = #timers, 1, -1 do |
86 local timer = timers[i]; | 86 local timer = timers[i]; |
87 local t, f = timer[1], timer[2]; | 87 local t, f = timer[1], timer[2]; |
88 local now = gettime(); -- inside or before the loop? | 88 -- Get time for every iteration to increase accuracy |
89 local now = gettime(); | |
89 if t > now then | 90 if t > now then |
90 -- This timer should not fire yet | 91 -- This timer should not fire yet |
91 local diff = t - now; | 92 local diff = t - now; |
92 if diff < next_delay then | 93 if diff < next_delay then |
93 next_delay = diff; | 94 next_delay = diff; |
94 end | 95 end |
95 break; | 96 break; |
96 end | 97 end |
97 local new_timeout = f(now); | 98 local new_timeout = f(now); |
98 if new_timeout then | 99 if new_timeout then |
100 -- Schedlue for 'delay' from the time actually sheduled, | |
101 -- not from now, in order to prevent timer drift. | |
99 timer[1] = t + new_timeout; | 102 timer[1] = t + new_timeout; |
100 resort_timers = true; | 103 resort_timers = true; |
101 else | 104 else |
102 t_remove(timers, i); | 105 t_remove(timers, i); |
103 end | 106 end |
485 | 488 |
486 function interface:resume() | 489 function interface:resume() |
487 self:setflags(true); | 490 self:setflags(true); |
488 end | 491 end |
489 | 492 |
493 -- Pause connection for some time | |
490 function interface:pausefor(t) | 494 function interface:pausefor(t) |
491 if self._pausefor then | 495 if self._pausefor then |
492 self._pausefor:close(); | 496 self._pausefor:close(); |
493 end | 497 end |
494 if t == false then return; end | 498 if t == false then return; end |