diff rlgwebd.js @ 49:423ef87ddc9b

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.
author John "Elwin" Edwards <elwin@sdf.org>
date Mon, 11 Jun 2012 09:15:33 -0700
parents 27b7f0c8b9f0
children 96815eae4ebe
line wrap: on
line diff
--- a/rlgwebd.js	Sat Jun 09 21:42:24 2012 -0700
+++ b/rlgwebd.js	Mon Jun 11 09:15:33 2012 -0700
@@ -72,6 +72,8 @@
   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 @@
       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 @@
   res.writeHead(200, resheaders);
   res.write(JSON.stringify({"t": "q"}));
   res.end();
+  term.sendq = true;
   return;
 }
 
@@ -653,8 +656,10 @@
       if (term.alive)
         reply.t = "n";
       else {
-        if (allowlogin)
+        if (allowlogin) {
           reply.t = "q";
+          term.sendq = true;
+        }
         else {
           sendError(res, 6, null);
           return;