Changeset

3042:b1961f6c9853

mod_bosh: Always give requests a destroy handler, so that the management of each session's request array and the inactive_sessions logic can happen in one place. Simplifies everything and concludes this series of BOSH fixes.
author Matthew Wild <mwild1@gmail.com>
date Mon, 17 May 2010 11:49:24 +0100
parents 3041:7489ac1d5938
children 3043:1fadbb2e3ca0 3046:92173d8a35d3
files plugins/mod_bosh.lua
diffstat 1 files changed, 15 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_bosh.lua	Mon May 17 11:46:54 2010 +0100
+++ b/plugins/mod_bosh.lua	Mon May 17 11:49:24 2010 +0100
@@ -73,6 +73,8 @@
 	--log("debug", "Handling new request %s: %s\n----------", request.id, tostring(body));
 	request.notopen = true;
 	request.log = log;
+	request.on_destroy = on_destroy_request;
+	
 	local parser = lxp.new(init_xmlhandlers(request, stream_callbacks), "\1");
 	
 	parser:parse(body);
@@ -101,14 +103,21 @@
 			session.send(resp);
 		end
 		
-		if not request.destroyed and session.bosh_wait then
-			request.reply_before = os_time() + session.bosh_wait;
-			request.on_destroy = on_destroy_request;
-			waiting_requests[request] = true;
+		if not request.destroyed then
+			-- We're keeping this request open, to respond later
+			log("debug", "Have nothing to say, so leaving request unanswered for now");
+			if session.bosh_wait then
+				request.reply_before = os_time() + session.bosh_wait;
+				waiting_requests[request] = true;
+			end
+			if inactive_sessions[session] then
+				-- Session was marked as inactive, since we have
+				-- a request open now, unmark it
+				inactive_sessions[session] = nil;
+			end
 		end
 		
-		log("debug", "Have nothing to say, so leaving request unanswered for now");
-		return true;
+		return true; -- Inform httpserver we shall reply later
 	end
 end
 
@@ -171,7 +180,6 @@
 				else
 					log("debug", "Destroying the request now...");
 					oldest_request:destroy();
-					t_remove(r, 1);
 				end
 			elseif s ~= "" then
 				log("debug", "Saved to send buffer because there are %d open requests", #r);
@@ -228,12 +236,6 @@
 		return;
 	end
 	
-	-- If session was inactive, make sure it is now marked as not
-	if #session.requests == 0 then
-		(session.log or log)("debug", "BOSH client now active again at %d", os_time());
-		inactive_sessions[session] = nil;
-	end
-	
 	if session.notopen then
 		local features = st.stanza("stream:features");
 		fire_event("stream-features", session, features);