Skip to content

Commit

Permalink
Fixed output buffering in AbstractServer.
Browse files Browse the repository at this point in the history
A pass-by-value bug was causing output chunks to be dropped if they
did not contain a line feed.

This fix also fixes an intermittent bug with pyOCD integration where
the line containing "GDB server started" was dropped.
  • Loading branch information
mcgordonite authored and thegecko committed Apr 20, 2020
1 parent 88b0b55 commit 6b1070c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/abstract-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,23 @@ export abstract class AbstractServer extends EventEmitter {
}

protected onStdout(chunk: string | Buffer) {
this.onData(chunk, this.outBuffer, 'stdout');
this.onData(chunk, 'stdout');
}

protected onStderr(chunk: string | Buffer) {
this.onData(chunk, this.errBuffer, 'stderr');
this.onData(chunk, 'stderr');
}

protected onData(chunk: string | Buffer, buffer: string, event: string) {
buffer += typeof chunk === 'string' ? chunk
: chunk.toString('utf8');
protected onData(chunk: string | Buffer, event: 'stdout' | 'stderr') {
const bufferName = event === 'stdout' ? 'outBuffer' : 'errBuffer';
this[bufferName] += typeof chunk === 'string' ? chunk : chunk.toString('utf8');

const end = buffer.lastIndexOf('\n');
const end = this[bufferName].lastIndexOf('\n');
if (end !== -1) {
const data = buffer.substring(0, end);
const data = this[bufferName].substring(0, end);
this.emit(event, data);
this.handleData(data);
buffer = buffer.substring(end + 1);
this[bufferName] = this[bufferName].substring(end + 1);
}
}

Expand Down

0 comments on commit 6b1070c

Please sign in to comment.