aboutsummaryrefslogtreecommitdiffstats
path: root/net/server_epoll.lua
diff options
context:
space:
mode:
Diffstat (limited to 'net/server_epoll.lua')
-rw-r--r--net/server_epoll.lua22
1 files changed, 20 insertions, 2 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua
index 53a67dd5..c47e1a70 100644
--- a/net/server_epoll.lua
+++ b/net/server_epoll.lua
@@ -58,6 +58,9 @@ local default_config = { __index = {
-- Maximum and minimum amount of time to sleep waiting for events (adjusted for pending timers)
max_wait = 86400;
min_wait = 1e-06;
+
+ --- How long to wait after getting the shutdown signal before forcefully tearing down every socket
+ shutdown_deadline = 5;
}};
local cfg = default_config.__index;
@@ -122,8 +125,8 @@ local function runtimers(next_delay, min_wait)
end
if readd then
- for _, timer in pairs(readd) do
- timers:insert(timer, timer[1]);
+ for id, timer in pairs(readd) do
+ timers:insert(timer, timer[1], id);
end
peek = timers:peek();
end
@@ -743,6 +746,21 @@ local function setquitting(quit)
if quit then
quitting = "quitting";
closeall();
+ addtimer(1, function ()
+ if quitting then
+ closeall();
+ return 1;
+ end
+ end);
+ if cfg.shutdown_deadline then
+ addtimer(cfg.shutdown_deadline, function ()
+ if quitting then
+ for fd, conn in pairs(fds) do -- luacheck: ignore 213/fd
+ conn:destroy();
+ end
+ end
+ end);
+ end
else
quitting = nil;
end