Software /
code /
prosody
Comparison
plugins/mod_bosh.lua @ 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 |
parent | 3041:7489ac1d5938 |
child | 3043:1fadbb2e3ca0 |
comparison
equal
deleted
inserted
replaced
3041:7489ac1d5938 | 3042:b1961f6c9853 |
---|---|
71 return; | 71 return; |
72 end | 72 end |
73 --log("debug", "Handling new request %s: %s\n----------", request.id, tostring(body)); | 73 --log("debug", "Handling new request %s: %s\n----------", request.id, tostring(body)); |
74 request.notopen = true; | 74 request.notopen = true; |
75 request.log = log; | 75 request.log = log; |
76 request.on_destroy = on_destroy_request; | |
77 | |
76 local parser = lxp.new(init_xmlhandlers(request, stream_callbacks), "\1"); | 78 local parser = lxp.new(init_xmlhandlers(request, stream_callbacks), "\1"); |
77 | 79 |
78 parser:parse(body); | 80 parser:parse(body); |
79 | 81 |
80 local session = sessions[request.sid]; | 82 local session = sessions[request.sid]; |
99 local resp = t_concat(session.send_buffer); | 101 local resp = t_concat(session.send_buffer); |
100 session.send_buffer = {}; | 102 session.send_buffer = {}; |
101 session.send(resp); | 103 session.send(resp); |
102 end | 104 end |
103 | 105 |
104 if not request.destroyed and session.bosh_wait then | 106 if not request.destroyed then |
105 request.reply_before = os_time() + session.bosh_wait; | 107 -- We're keeping this request open, to respond later |
106 request.on_destroy = on_destroy_request; | 108 log("debug", "Have nothing to say, so leaving request unanswered for now"); |
107 waiting_requests[request] = true; | 109 if session.bosh_wait then |
108 end | 110 request.reply_before = os_time() + session.bosh_wait; |
109 | 111 waiting_requests[request] = true; |
110 log("debug", "Have nothing to say, so leaving request unanswered for now"); | 112 end |
111 return true; | 113 if inactive_sessions[session] then |
114 -- Session was marked as inactive, since we have | |
115 -- a request open now, unmark it | |
116 inactive_sessions[session] = nil; | |
117 end | |
118 end | |
119 | |
120 return true; -- Inform httpserver we shall reply later | |
112 end | 121 end |
113 end | 122 end |
114 | 123 |
115 | 124 |
116 local function bosh_reset_stream(session) session.notopen = true; end | 125 local function bosh_reset_stream(session) session.notopen = true; end |
169 t_remove(r, 1); | 178 t_remove(r, 1); |
170 end | 179 end |
171 else | 180 else |
172 log("debug", "Destroying the request now..."); | 181 log("debug", "Destroying the request now..."); |
173 oldest_request:destroy(); | 182 oldest_request:destroy(); |
174 t_remove(r, 1); | |
175 end | 183 end |
176 elseif s ~= "" then | 184 elseif s ~= "" then |
177 log("debug", "Saved to send buffer because there are %d open requests", #r); | 185 log("debug", "Saved to send buffer because there are %d open requests", #r); |
178 -- Hmm, no requests are open :( | 186 -- Hmm, no requests are open :( |
179 t_insert(session.send_buffer, tostring(s)); | 187 t_insert(session.send_buffer, tostring(s)); |
226 session:close(); | 234 session:close(); |
227 request.notopen = nil; | 235 request.notopen = nil; |
228 return; | 236 return; |
229 end | 237 end |
230 | 238 |
231 -- If session was inactive, make sure it is now marked as not | |
232 if #session.requests == 0 then | |
233 (session.log or log)("debug", "BOSH client now active again at %d", os_time()); | |
234 inactive_sessions[session] = nil; | |
235 end | |
236 | |
237 if session.notopen then | 239 if session.notopen then |
238 local features = st.stanza("stream:features"); | 240 local features = st.stanza("stream:features"); |
239 fire_event("stream-features", session, features); | 241 fire_event("stream-features", session, features); |
240 session.send(features); | 242 session.send(features); |
241 session.notopen = nil; | 243 session.notopen = nil; |