From db55f3f83cc1203891b537e0e525037f6856b11f Mon Sep 17 00:00:00 2001 From: "John \"Elwin\" Edwards" Date: Tue, 15 May 2012 16:26:28 -0700 Subject: [PATCH] webtty.js: check message order. Implement checking the numbers of the client's messages on the server. Fixing out-of-ordering isn't implemented because the problem hasn't been observed yet, though it likely will once actual network transit is involved. --- webtty.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/webtty.js b/webtty.js index e06073d..26ff927 100755 --- a/webtty.js +++ b/webtty.js @@ -38,8 +38,10 @@ function TermSession(sessid, h, w) { /* Eventually we'll need to make sure the sessid isn't in use yet. */ this.sessid = sessid; this.alive = true; - this.data = []; - this.nsend = 0; + this.data = []; // Buffer for the process' output. + this.nsend = 0; // Number to use for the next message sent. + this.nrecv = 0; // Number expected on the next message received. + this.msgQ = []; // Queue for messages that arrived out of order. this.child.stdout.on("data", function (buf) { ss.data.push(buf); }); @@ -52,10 +54,16 @@ function TermSession(sessid, h, w) { /* Wait for all the data to get collected */ setTimeout(ss.cleanup, 1000); }); - this.write = function (data) { - if (this.alive) - this.child.stdin.write(data); - /* Otherwise, throw some kind of exception? */ + this.write = function (data, n) { + if (!this.alive) { + /* Throw some kind of exception? */ + return; + } + if (n !== this.nrecv) { + console.log("Session " + this.sessid + ": Expected message " + this.nrecv + ", got " + n); + } + this.nrecv = n + 1; + this.child.stdin.write(data); }; this.read = function () { if (this.data.length == 0) @@ -303,7 +311,7 @@ function handler(req, res) { return; } keybuf = new Buffer(hexstr, "hex"); - cterm.write(keybuf); + cterm.write(keybuf, formdata["n"]); } readFeed(res, cterm); }