Fix further crashes when following dgamelaunch games.
The crashes apparently resulted from reading a ttyrec header and then trying to read the data chunk before dgamelaunch produced it. When the data chunk did become available, it would be read by the header function. The simplest solution was to store the position for reading the ttyrec file in the DGLSession, and to leave it unchanged if anything unexpected occurs when reading.
This commit is contained in:
parent
6b0ed5280b
commit
56024418c3
1 changed files with 17 additions and 4 deletions
21
rlgwebd.js
21
rlgwebd.js
|
|
@ -258,6 +258,7 @@ function DglSession(filename) {
|
||||||
/* Flag to prevent multiple handlers from reading simultaneously and
|
/* Flag to prevent multiple handlers from reading simultaneously and
|
||||||
* getting into a race. */
|
* getting into a race. */
|
||||||
this.reading = false;
|
this.reading = false;
|
||||||
|
this.rpos = 0;
|
||||||
this.framebuf = new Buffer(1024);
|
this.framebuf = new Buffer(1024);
|
||||||
this.frameoff = 0;
|
this.frameoff = 0;
|
||||||
this.framepush = function(chunk) {
|
this.framepush = function(chunk) {
|
||||||
|
|
@ -286,24 +287,36 @@ function DglSession(filename) {
|
||||||
return;
|
return;
|
||||||
this.reading = true;
|
this.reading = true;
|
||||||
var header = new Buffer(12);
|
var header = new Buffer(12);
|
||||||
fs.read(ss.fd, header, 0, 12, null, function (err, n, buf) {
|
fs.read(ss.fd, header, 0, 12, ss.rpos, function (err, n, buf) {
|
||||||
/* Stop recursion if end of file has been reached. */
|
/* Stop recursion if end of file has been reached. */
|
||||||
if (err || n < 12) {
|
if (err || n < 12) {
|
||||||
|
if (!err && n > 0) {
|
||||||
|
tslog("DGL %s: expected 12-byte header, got %d", ss.tag(), n);
|
||||||
|
}
|
||||||
ss.reading = false;
|
ss.reading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ss.rpos += 12;
|
||||||
var datalen = buf.readUInt32LE(8);
|
var datalen = buf.readUInt32LE(8);
|
||||||
//tslog("Allocating %d bytes", datalen);
|
//tslog("Allocating %d bytes", datalen);
|
||||||
|
if (datalen > 16384) {
|
||||||
|
tslog("DGL %s: looking for %d bytes", ss.tag(), datalen);
|
||||||
|
}
|
||||||
var databuf = new Buffer(datalen);
|
var databuf = new Buffer(datalen);
|
||||||
fs.read(ss.fd, databuf, 0, datalen, null, function (err, n, buf) {
|
fs.read(ss.fd, databuf, 0, datalen, ss.rpos, function (err, n, buf) {
|
||||||
ss.reading = false;
|
|
||||||
if (err || n < datalen) {
|
if (err || n < datalen) {
|
||||||
|
/* Next time, read the header again. */
|
||||||
|
ss.rpos -= 12;
|
||||||
|
ss.reading = false;
|
||||||
|
tslog("DGL %s: expected %d bytes, got %d", ss.tag(), datalen, n);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ss.rpos += n;
|
||||||
|
ss.reading = false;
|
||||||
/* Process the data */
|
/* Process the data */
|
||||||
ss.framepush(buf);
|
ss.framepush(buf);
|
||||||
ss.emit("data", buf);
|
ss.emit("data", buf);
|
||||||
tslog("DGL %s: %d bytes", ss.tag(), buf.length);
|
//tslog("DGL %s: %d bytes", ss.tag(), buf.length);
|
||||||
/* Recurse. */
|
/* Recurse. */
|
||||||
ss.readchunk();
|
ss.readchunk();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue