Comparison

net/server_epoll.lua @ 7687:ae24deae6488

net.server_epoll: Separate ok from err branch more
author Kim Alvefur <zash@zash.se>
date Fri, 07 Oct 2016 17:18:29 +0200
parent 7658:e14a124c4d73
child 7691:a5ad858f3a93
comparison
equal deleted inserted replaced
7686:8d6f367bed8c 7687:ae24deae6488
288 end 288 end
289 289
290 -- Called when socket is readable 290 -- Called when socket is readable
291 function interface:onreadable() 291 function interface:onreadable()
292 local data, err, partial = self.conn:receive(self._pattern); 292 local data, err, partial = self.conn:receive(self._pattern);
293 if data then
294 self:on("incoming", data);
295 else
296 if partial then
297 self:on("incoming", partial, err);
298 end
299 if err == "wantread" then
300 self:setflags(true, nil);
301 elseif err == "wantwrite" then
302 self:setflags(nil, true);
303 elseif err ~= "timeout" then
304 self:on("disconnect", err);
305 self:destroy()
306 return;
307 end
308 end
293 if self.conn:dirty() then 309 if self.conn:dirty() then
294 self:setreadtimeout(false); 310 self:setreadtimeout(false);
295 self:pausefor(cfg.read_retry_delay); 311 self:pausefor(cfg.read_retry_delay);
296 else 312 else
297 self:setreadtimeout(); 313 self:setreadtimeout();
298 end
299 if data or partial then
300 self:on("incoming", data or partial, err);
301 end
302 if err == "wantread" then
303 self:setflags(true, nil);
304 elseif err == "wantwrite" then
305 self:setflags(nil, true);
306 elseif not data and err ~= "timeout" then
307 self:on("disconnect", err);
308 self:destroy()
309 return;
310 end 314 end
311 end 315 end
312 316
313 -- Called when socket is writable 317 -- Called when socket is writable
314 function interface:onwriteable() 318 function interface:onwriteable()
321 end 325 end
322 self:setflags(nil, false); 326 self:setflags(nil, false);
323 self:setwritetimeout(false); 327 self:setwritetimeout(false);
324 self:ondrain(); -- Be aware of writes in ondrain 328 self:ondrain(); -- Be aware of writes in ondrain
325 return; 329 return;
326 elseif partial then 330 end
331 if partial then
327 buffer[1] = data:sub(partial+1); 332 buffer[1] = data:sub(partial+1);
328 for i = #buffer, 2, -1 do 333 for i = #buffer, 2, -1 do
329 buffer[i] = nil; 334 buffer[i] = nil;
330 end 335 end
331 self:setwritetimeout(); 336 self:setwritetimeout();
332 end 337 end
333 if err == "wantwrite" or err == "timeout" then 338 if err == "wantwrite" or err == "timeout" then
334 self:setflags(nil, true); 339 self:setflags(nil, true);
335 elseif err == "wantread" then 340 elseif err == "wantread" then
336 self:setflags(true, nil); 341 self:setflags(true, nil);
337 elseif err and err ~= "timeout" then 342 elseif err ~= "timeout" then
338 self:on("disconnect", err); 343 self:on("disconnect", err);
339 self:destroy(); 344 self:destroy();
340 end 345 end
341 end 346 end
342 347