-
- if co_running() ~= session.thread and not session.paused then
- if session.state == "wait" then
- session.state = "ready";
- local ok, state = co_resume(session.thread);
- if not ok then
- log("error", "Traceback[c2s]: %s", state);
- elseif state == "wait" then
- return;
- end
- end
- -- We're not currently running, so start the thread to process pending stanzas
- local s, thread = session.pending_stanzas, session.thread;
- local n = #s;
- while n > 0 and session.state ~= "wait" do
- session.log("debug", "processing %d stanzas", n);
- local consumed;
- for i = 1,n do
- local stanza = s[i];
- local ok, state = co_resume(thread, stanza);
- if not ok then
- log("error", "Traceback[c2s]: %s", state);
- elseif state == "wait" then
- consumed = i;
- session.state = "wait";
- break;
- end
- end
- if not consumed then consumed = n; end
- for i = 1, #s do
- s[i] = s[consumed+i];
- end
- n = #s;
- end
- end