Changeset

323:5bf3b13edb80

verse.client: Try to behave better when stream is closed gracefully
author Kim Alvefur <zash@zash.se>
date Sun, 10 Feb 2013 02:53:03 +0100
parents 322:819b35b8fcf6
children 324:dbb3362c1ff3
files client.lua
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/client.lua	Sun Feb 10 02:50:02 2013 +0100
+++ b/client.lua	Sun Feb 10 02:53:03 2013 +0100
@@ -32,7 +32,12 @@
 end
 
 function stream_callbacks.streamclosed(stream)
-	return stream:event("closed");
+	if not stream.notopen then
+		stream:send("</stream:stream>");
+		stream.notopen = true;
+	end
+	stream:event("closed");
+	return stream:close("stream closed")
 end
 
 function stream_callbacks.handlestanza(stream, stanza)
@@ -129,10 +134,13 @@
 
 	local _base_close = self.close;
 	function self:close(reason)
+		self.close = _base_close;
 		if not self.notopen then
 			self:send("</stream:stream>");
+			self.notopen = true;
+		else
+			return self:close(reason);
 		end
-		return _base_close(self);
 	end
 	
 	local function start_connect()