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.
This commit is contained in:
John "Elwin" Edwards 2012-05-15 16:26:28 -07:00
parent c7995adad5
commit db55f3f83c

View file

@ -38,8 +38,10 @@ function TermSession(sessid, h, w) {
/* Eventually we'll need to make sure the sessid isn't in use yet. */ /* Eventually we'll need to make sure the sessid isn't in use yet. */
this.sessid = sessid; this.sessid = sessid;
this.alive = true; this.alive = true;
this.data = []; this.data = []; // Buffer for the process' output.
this.nsend = 0; 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) { this.child.stdout.on("data", function (buf) {
ss.data.push(buf); ss.data.push(buf);
}); });
@ -52,10 +54,16 @@ function TermSession(sessid, h, w) {
/* Wait for all the data to get collected */ /* Wait for all the data to get collected */
setTimeout(ss.cleanup, 1000); setTimeout(ss.cleanup, 1000);
}); });
this.write = function (data) { this.write = function (data, n) {
if (this.alive) if (!this.alive) {
this.child.stdin.write(data); /* Throw some kind of exception? */
/* Otherwise, 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 () { this.read = function () {
if (this.data.length == 0) if (this.data.length == 0)
@ -303,7 +311,7 @@ function handler(req, res) {
return; return;
} }
keybuf = new Buffer(hexstr, "hex"); keybuf = new Buffer(hexstr, "hex");
cterm.write(keybuf); cterm.write(keybuf, formdata["n"]);
} }
readFeed(res, cterm); readFeed(res, cterm);
} }