clix.lua: Close connection immediately rather than delaying if send buffer is empty (thanks Florob)

Tue, 14 Dec 2010 20:18:56 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 14 Dec 2010 20:18:56 +0000
changeset 45
36f5bf718d3c
parent 44
3c3cc6d75814
child 46
b5d6e443e571

clix.lua: Close connection immediately rather than delaying if send buffer is empty (thanks Florob)

clix.lua file | annotate | diff | comparison | revisions
--- a/clix.lua	Wed Sep 15 16:54:21 2010 +0100
+++ b/clix.lua	Tue Dec 14 20:18:56 2010 +0000
@@ -101,7 +101,7 @@
 	local _real_close = conn.close;
 	function conn:close()
 		conn:debug("Delaying close...");
-		conn:hook("drained", function ()
+		local function close_conn()
 			local function do_close()
 				if _real_close then
 					conn:debug("Closing now...");
@@ -116,7 +116,12 @@
 			else
 				do_close();
 			end
-		end);
+		end
+		if conn.conn:bufferlen() == 0 then
+			close_conn();
+		else
+			conn:hook("drained", close_conn);
+		end
 	end
 	-- /COMPAT
 	

mercurial