From 4cdac4facbd5f8445ad3b6aaae8a7ac032c970d0 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Sun, 1 Jan 2017 19:34:18 +0100
Subject: server_epoll: Flush and close all connections before quitting
 mainloop so no data is lost in buffers

---
 net/server_epoll.lua | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/server_epoll.lua b/net/server_epoll.lua
index d5f9d266..274368b0 100644
--- a/net/server_epoll.lua
+++ b/net/server_epoll.lua
@@ -15,6 +15,7 @@ local t_concat = table.concat;
 local setmetatable = setmetatable;
 local tostring = tostring;
 local pcall = pcall;
+local next = next;
 local pairs = pairs;
 local log = require "util.logger".init("server_epoll");
 local epoll = require "epoll";
@@ -615,6 +616,7 @@ local quitting = nil;
 local function setquitting(quit)
 	if quit then
 		quitting = "quitting";
+		closeall();
 	else
 		quitting = nil;
 	end
@@ -641,7 +643,7 @@ local function loop(once)
 		elseif r ~= "timeout" then
 			log("debug", "epoll_wait error: %s", tostring(r));
 		end
-	until once or quitting;
+	until once or (quitting and next(fds) == nil);
 	return quitting;
 end
 
-- 
cgit v1.2.3