Mercurial > hg > rlgwebd
comparison webtty.js @ 15:7466927c17a5
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.
| author | John "Elwin" Edwards <elwin@sdf.org> |
|---|---|
| date | Tue, 15 May 2012 16:26:28 -0700 |
| parents | bf7c26d0b66d |
| children | e4773ac5d4d5 |
comparison
equal
deleted
inserted
replaced
| 14:155f3c104759 | 15:7466927c17a5 |
|---|---|
| 36 this.child = child_process.spawn(ptyhelp, ["bash"], spawnopts); | 36 this.child = child_process.spawn(ptyhelp, ["bash"], spawnopts); |
| 37 var ss = this; | 37 var ss = this; |
| 38 /* Eventually we'll need to make sure the sessid isn't in use yet. */ | 38 /* Eventually we'll need to make sure the sessid isn't in use yet. */ |
| 39 this.sessid = sessid; | 39 this.sessid = sessid; |
| 40 this.alive = true; | 40 this.alive = true; |
| 41 this.data = []; | 41 this.data = []; // Buffer for the process' output. |
| 42 this.nsend = 0; | 42 this.nsend = 0; // Number to use for the next message sent. |
| 43 this.nrecv = 0; // Number expected on the next message received. | |
| 44 this.msgQ = []; // Queue for messages that arrived out of order. | |
| 43 this.child.stdout.on("data", function (buf) { | 45 this.child.stdout.on("data", function (buf) { |
| 44 ss.data.push(buf); | 46 ss.data.push(buf); |
| 45 }); | 47 }); |
| 46 this.child.stderr.on("data", function (buf) { | 48 this.child.stderr.on("data", function (buf) { |
| 47 ss.data.push(buf); | 49 ss.data.push(buf); |
| 50 ss.exitcode = (code != null ? code : 255); | 52 ss.exitcode = (code != null ? code : 255); |
| 51 ss.alive = false; | 53 ss.alive = false; |
| 52 /* Wait for all the data to get collected */ | 54 /* Wait for all the data to get collected */ |
| 53 setTimeout(ss.cleanup, 1000); | 55 setTimeout(ss.cleanup, 1000); |
| 54 }); | 56 }); |
| 55 this.write = function (data) { | 57 this.write = function (data, n) { |
| 56 if (this.alive) | 58 if (!this.alive) { |
| 57 this.child.stdin.write(data); | 59 /* Throw some kind of exception? */ |
| 58 /* Otherwise, throw some kind of exception? */ | 60 return; |
| 61 } | |
| 62 if (n !== this.nrecv) { | |
| 63 console.log("Session " + this.sessid + ": Expected message " + this.nrecv + ", got " + n); | |
| 64 } | |
| 65 this.nrecv = n + 1; | |
| 66 this.child.stdin.write(data); | |
| 59 }; | 67 }; |
| 60 this.read = function () { | 68 this.read = function () { |
| 61 if (this.data.length == 0) | 69 if (this.data.length == 0) |
| 62 return null; | 70 return null; |
| 63 var pos = 0; | 71 var pos = 0; |
| 301 if (hexstr.length % 2 != 0) { | 309 if (hexstr.length % 2 != 0) { |
| 302 sendError(res, 2); | 310 sendError(res, 2); |
| 303 return; | 311 return; |
| 304 } | 312 } |
| 305 keybuf = new Buffer(hexstr, "hex"); | 313 keybuf = new Buffer(hexstr, "hex"); |
| 306 cterm.write(keybuf); | 314 cterm.write(keybuf, formdata["n"]); |
| 307 } | 315 } |
| 308 readFeed(res, cterm); | 316 readFeed(res, cterm); |
| 309 } | 317 } |
| 310 else if (target == "/login") { | 318 else if (target == "/login") { |
| 311 login(req, res, formdata); | 319 login(req, res, formdata); |
