30 |
30 |
31 -- Used to respond to idle sessions (those with waiting requests) |
31 -- Used to respond to idle sessions (those with waiting requests) |
32 local waiting_requests = {}; |
32 local waiting_requests = {}; |
33 function on_destroy_request(request) |
33 function on_destroy_request(request) |
34 waiting_requests[request] = nil; |
34 waiting_requests[request] = nil; |
|
35 local session = request.session; |
|
36 if session then |
|
37 local requests = session.requests; |
|
38 for i,r in pairs(requests) do |
|
39 if r == request then requests[i] = nil; break; end |
|
40 end |
|
41 |
|
42 -- If this session now has no requests open, mark it as inactive |
|
43 if #requests == 0 and session.bosh_max_inactive and not inactive_sessions[session] then |
|
44 inactive_sessions[session] = os_time(); |
|
45 (session.log or log)("debug", "BOSH session marked as inactive at %d", inactive_sessions[session]); |
|
46 end |
|
47 end |
35 end |
48 end |
36 |
49 |
37 function handle_request(method, body, request) |
50 function handle_request(method, body, request) |
38 if (not body) or request.method ~= "POST" then |
51 if (not body) or request.method ~= "POST" then |
39 return "<html><body>You really don't look like a BOSH client to me... what do you want?</body></html>"; |
52 return "<html><body>You really don't look like a BOSH client to me... what do you want?</body></html>"; |
149 oldest_request:destroy(); |
162 oldest_request:destroy(); |
150 t_remove(r, 1); |
163 t_remove(r, 1); |
151 end |
164 end |
152 elseif s ~= "" then |
165 elseif s ~= "" then |
153 log("debug", "Saved to send buffer because there are %d open requests", #r); |
166 log("debug", "Saved to send buffer because there are %d open requests", #r); |
154 if session.bosh_max_inactive and not inactive_sessions[session] then |
|
155 inactive_sessions[session] = os_time(); |
|
156 (session.log or log)("debug", "BOSH session marked as inactive at %d", inactive_sessions[session]); |
|
157 end |
|
158 -- Hmm, no requests are open :( |
167 -- Hmm, no requests are open :( |
159 t_insert(session.send_buffer, tostring(s)); |
168 t_insert(session.send_buffer, tostring(s)); |
160 log("debug", "There are now %d things in the send_buffer", #session.send_buffer); |
169 log("debug", "There are now %d things in the send_buffer", #session.send_buffer); |
161 end |
170 end |
162 end |
171 end |
241 if session.bosh_max_inactive then |
250 if session.bosh_max_inactive then |
242 if now - inactive_since > session.bosh_max_inactive then |
251 if now - inactive_since > session.bosh_max_inactive then |
243 (session.log or log)("debug", "BOSH client inactive too long, destroying session at %d", now); |
252 (session.log or log)("debug", "BOSH client inactive too long, destroying session at %d", now); |
244 sessions[session.sid] = nil; |
253 sessions[session.sid] = nil; |
245 inactive_sessions[session] = nil; |
254 inactive_sessions[session] = nil; |
246 session.bosh_max_inactive = nil; -- Stop us marking this session as active during destroy |
|
247 sm_destroy_session(session, "BOSH client silent for over "..session.bosh_max_inactive.." seconds"); |
255 sm_destroy_session(session, "BOSH client silent for over "..session.bosh_max_inactive.." seconds"); |
248 end |
256 end |
249 else |
257 else |
250 inactive_sessions[session] = nil; |
258 inactive_sessions[session] = nil; |
251 end |
259 end |