clix.lua

changeset 40
c74380af7075
parent 38
eb9f706324c7
child 41
89070edde205
--- 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

mercurial