From c7cb905b298e4dca35960db769fc0c76b7ee809b Mon Sep 17 00:00:00 2001 From: "John \"Elwin\" Edwards" Date: Mon, 11 Jun 2012 09:15:33 -0700 Subject: [PATCH] RLG-Web: delay removing TermSessions until the client is informed. Add a TermSession.sendq flag that indicates whether a type q message has been sent to the client. Don't immediately destroy the TermSession on child exit if the message hasn't been sent. This is an ugly hack until the TermSession class is separated into an EventEmitter to handle the PTY and a listening object that handles communication with the client. That will also allow other clients to watch the game. --- rlgwebd.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rlgwebd.js b/rlgwebd.js index 028fda3..c22701a 100755 --- a/rlgwebd.js +++ b/rlgwebd.js @@ -72,6 +72,8 @@ function TermSession(game, user, dims, lkey) { this.key = lkey; /* This order seems to best avoid race conditions... */ this.alive = false; + // A kludge until TermSession is rewritten to handle real watching. + this.sendq = false; this.sessid = randkey(2); while (this.sessid in sessions) { this.sessid = randkey(2); @@ -218,7 +220,7 @@ function TermSession(game, user, dims, lkey) { return; ss.record.end(); /* Give the client a chance to read any leftover data. */ - if (ss.data.length > 0) + if (ss.data.length > 0 || !ss.sendq) setTimeout(ss.remove, 8000); else ss.remove(); @@ -582,6 +584,7 @@ function endgame(term, res) { res.writeHead(200, resheaders); res.write(JSON.stringify({"t": "q"})); res.end(); + term.sendq = true; return; } @@ -653,8 +656,10 @@ function readFeed(res, term) { if (term.alive) reply.t = "n"; else { - if (allowlogin) + if (allowlogin) { reply.t = "q"; + term.sendq = true; + } else { sendError(res, 6, null); return;