Comparison

plugins/mod_bosh.lua @ 4436:aa79b3767f98

mod_bosh: Store time to destroy session in inactive_sessions, removing dependency on session.bosh_max_inactive in cleanup timer
author Matthew Wild <mwild1@gmail.com>
date Wed, 07 Dec 2011 02:58:22 +0000
parent 4379:e4d88f4a780c
child 4437:916681a9a7be
comparison
equal deleted inserted replaced
4435:ea69296afaef 4436:aa79b3767f98
89 break; 89 break;
90 end 90 end
91 end 91 end
92 92
93 -- If this session now has no requests open, mark it as inactive 93 -- If this session now has no requests open, mark it as inactive
94 if #requests == 0 and session.bosh_max_inactive and not inactive_sessions[session] then 94 local max_inactive = session.bosh_max_inactive;
95 inactive_sessions[session] = os_time(); 95 if max_inactive and #requests == 0 then
96 (session.log or log)("debug", "BOSH session marked as inactive at %d", inactive_sessions[session]); 96 inactive_sessions[session] = os_time() + max_inactive;
97 (session.log or log)("debug", "BOSH session marked as inactive (for %ds)", max_inactive);
97 end 98 end
98 end 99 end
99 end 100 end
100 101
101 function handle_request(method, body, request) 102 function handle_request(method, body, request)
400 end 401 end
401 end 402 end
402 403
403 now = now - 3; 404 now = now - 3;
404 local n_dead_sessions = 0; 405 local n_dead_sessions = 0;
405 for session, inactive_since in pairs(inactive_sessions) do 406 for session, close_after in pairs(inactive_sessions) do
406 if session.bosh_max_inactive then 407 if close_after < now then
407 if now - inactive_since > session.bosh_max_inactive then 408 (session.log or log)("debug", "BOSH client inactive too long, destroying session at %d", now);
408 (session.log or log)("debug", "BOSH client inactive too long, destroying session at %d", now); 409 sessions[session.sid] = nil;
409 sessions[session.sid] = nil;
410 inactive_sessions[session] = nil;
411 n_dead_sessions = n_dead_sessions + 1;
412 dead_sessions[n_dead_sessions] = session;
413 end
414 else
415 inactive_sessions[session] = nil; 410 inactive_sessions[session] = nil;
411 n_dead_sessions = n_dead_sessions + 1;
412 dead_sessions[n_dead_sessions] = session;
416 end 413 end
417 end 414 end
418 415
419 for i=1,n_dead_sessions do 416 for i=1,n_dead_sessions do
420 local session = dead_sessions[i]; 417 local session = dead_sessions[i];