# HG changeset patch # User John "Elwin" Edwards # Date 1337124388 25200 # Node ID 7466927c17a53a2aeb746f9652785910a644ec94 # Parent 155f3c104759c92ebfc3c9c86ec80b9077742542 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. diff -r 155f3c104759 -r 7466927c17a5 webtty.js --- a/webtty.js Tue May 15 09:30:12 2012 -0700 +++ b/webtty.js Tue May 15 16:26:28 2012 -0700 @@ -38,8 +38,10 @@ /* 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 @@ /* 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 @@ return; } keybuf = new Buffer(hexstr, "hex"); - cterm.write(keybuf); + cterm.write(keybuf, formdata["n"]); } readFeed(res, cterm); }