Comparison

net/server_epoll.lua @ 7558:3a2fe8e10eeb

net.server_epoll: Fix calculation of next timer event
author Kim Alvefur <zash@zash.se>
date Fri, 12 Aug 2016 00:25:19 +0200
parent 7557:f0dd902534b0
child 7559:b1b27dedf4cf
comparison
equal deleted inserted replaced
7557:f0dd902534b0 7558:3a2fe8e10eeb
77 if t > now then 77 if t > now then
78 local diff = t - now; 78 local diff = t - now;
79 if diff < next_delay then 79 if diff < next_delay then
80 next_delay = diff; 80 next_delay = diff;
81 end 81 end
82 return next_delay; 82 break;
83 end 83 end
84 local new_timeout = f(now); 84 local new_timeout = f(now);
85 if new_timeout then 85 if new_timeout then
86 local t_diff = t + new_timeout - now;
87 if t_diff < 1e-6 then
88 t_diff = 1e-6;
89 end
90 if t_diff < next_delay then
91 next_delay = t_diff;
92 end
93 timer[1] = t + new_timeout; 86 timer[1] = t + new_timeout;
94 resort_timers = true; 87 resort_timers = true;
95 else 88 else
96 t_remove(timers, i); 89 t_remove(timers, i);
97 end 90 end
98 end 91 end
99 if next_delay < 1e-6 then 92 if resort_timers or next_delay < 1e-6 then
93 -- Timers may be added from within a timer callback.
94 -- Those would not be considered for next_dela,
95 -- and we might sleep for too long, so instead
96 -- we return a shorter timeout so we can
97 -- properly sort all new timers.
100 next_delay = 1e-6; 98 next_delay = 1e-6;
101 end 99 end
102 return next_delay; 100 return next_delay;
103 end 101 end
104 102