Comparison

net/server_epoll.lua @ 11264:2cdcf55c6dd5

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Fri, 08 Jan 2021 23:56:27 +0100
parent 11239:06a5919e2496
parent 11262:2c559953ad41
child 11267:97077089f3c2
comparison
equal deleted inserted replaced
11260:08b397c21805 11264:2cdcf55c6dd5
117 local function runtimers(next_delay, min_wait) 117 local function runtimers(next_delay, min_wait)
118 -- Any timers at all? 118 -- Any timers at all?
119 local elapsed = monotonic(); 119 local elapsed = monotonic();
120 local now = realtime(); 120 local now = realtime();
121 local peek = timers:peek(); 121 local peek = timers:peek();
122 local readd;
122 while peek do 123 while peek do
123 124
124 if peek > elapsed then 125 if peek > elapsed then
125 next_delay = peek - elapsed;
126 break; 126 break;
127 end 127 end
128 128
129 local _, timer, id = timers:pop(); 129 local _, timer, id = timers:pop();
130 local ok, ret = xpcall(timer, traceback, now, id); 130 local ok, ret = xpcall(timer, traceback, now, id);
131 if ok and type(ret) == "number" then 131 if ok and type(ret) == "number" then
132 local next_time = elapsed+ret; 132 local next_time = elapsed+ret;
133 timers:insert(timer, next_time); 133 -- Delay insertion of timers to be re-added
134 -- so they don't get called again this tick
135 if readd then
136 readd[id] = { timer, next_time };
137 else
138 readd = { [id] = { timer, next_time } };
139 end
134 elseif not ok then 140 elseif not ok then
135 log("error", "Error in timer: %s", ret); 141 log("error", "Error in timer: %s", ret);
136 end 142 end
137 143
138 peek = timers:peek(); 144 peek = timers:peek();
139 end 145 end
146
147 if readd then
148 for _, timer in pairs(readd) do
149 timers:insert(timer[1], timer[2]);
150 end
151 peek = timers:peek();
152 end
153
140 if peek == nil then 154 if peek == nil then
141 return next_delay; 155 return next_delay;
156 else
157 next_delay = peek - elapsed;
142 end 158 end
143 159
144 if next_delay < min_wait then 160 if next_delay < min_wait then
145 return min_wait; 161 return min_wait;
146 end 162 end