Changeset

40:c74380af7075

clix.lua: Add workaround for Tigase bug which discards stanzas sent immediately before stream close, use --close-delay=X to delay close for some seconds
author Matthew Wild <mwild1@gmail.com>
date Tue, 24 Aug 2010 22:51:49 +0100
parents 39:4b08296a6748
children 41:89070edde205
files clix.lua
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/clix.lua	Tue Aug 24 10:55:49 2010 -0700
+++ b/clix.lua	Tue Aug 24 22:51:49 2010 +0100
@@ -94,6 +94,30 @@
 	-- Connect!
 	conn:connect_client(account.jid, opts.password or account.password);
 	
+	-- COMPAT: Tigase discards stanzas sent at the same time as </stream:stream>
+	local _real_close = conn.close;
+	function conn:close()
+		conn:debug("Delaying close...");
+		conn:hook("drained", function ()
+			local function do_close()
+				if _real_close then
+					conn:debug("Closing now...");
+					local close = _real_close;
+					_real_close = nil;
+					close(conn);
+				end
+			end
+			local close_delay = tonumber(opts.close_delay) or 0;
+			if close_delay > 0 then
+				verse.add_task(close_delay, do_close);
+			else
+				do_close();
+			end
+		end);
+	end
+	-- /COMPAT
+	
+	
 	if type(opts.resource) == "string" then
 		conn.resource = opts.resource;
 	end