Comparison

net/server_epoll.lua @ 7797:d0c32d86724f

server_epoll: Flush and close all connections before quitting mainloop so no data is lost in buffers
author Kim Alvefur <zash@zash.se>
date Sun, 01 Jan 2017 19:34:18 +0100
parent 7796:12609aee3b3b
child 7799:93643a61858a
comparison
equal deleted inserted replaced
7796:12609aee3b3b 7797:d0c32d86724f
13 local t_remove = table.remove; 13 local t_remove = table.remove;
14 local t_concat = table.concat; 14 local t_concat = table.concat;
15 local setmetatable = setmetatable; 15 local setmetatable = setmetatable;
16 local tostring = tostring; 16 local tostring = tostring;
17 local pcall = pcall; 17 local pcall = pcall;
18 local next = next;
18 local pairs = pairs; 19 local pairs = pairs;
19 local log = require "util.logger".init("server_epoll"); 20 local log = require "util.logger".init("server_epoll");
20 local epoll = require "epoll"; 21 local epoll = require "epoll";
21 local socket = require "socket"; 22 local socket = require "socket";
22 local luasec = require "ssl"; 23 local luasec = require "ssl";
613 614
614 -- Signal main loop about shutdown via above upvalue 615 -- Signal main loop about shutdown via above upvalue
615 local function setquitting(quit) 616 local function setquitting(quit)
616 if quit then 617 if quit then
617 quitting = "quitting"; 618 quitting = "quitting";
619 closeall();
618 else 620 else
619 quitting = nil; 621 quitting = nil;
620 end 622 end
621 end 623 end
622 624
639 epoll.ctl("del", fd); 641 epoll.ctl("del", fd);
640 end 642 end
641 elseif r ~= "timeout" then 643 elseif r ~= "timeout" then
642 log("debug", "epoll_wait error: %s", tostring(r)); 644 log("debug", "epoll_wait error: %s", tostring(r));
643 end 645 end
644 until once or quitting; 646 until once or (quitting and next(fds) == nil);
645 return quitting; 647 return quitting;
646 end 648 end
647 649
648 return { 650 return {
649 get_backend = function () return "epoll"; end; 651 get_backend = function () return "epoll"; end;