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. */
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);
}