Skip to content

Commit 6b1070c

Browse files
mcgordonitethegecko
authored andcommitted
Fixed output buffering in AbstractServer.
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.
1 parent 88b0b55 commit 6b1070c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/abstract-server.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,23 @@ export abstract class AbstractServer extends EventEmitter {
110110
}
111111

112112
protected onStdout(chunk: string | Buffer) {
113-
this.onData(chunk, this.outBuffer, 'stdout');
113+
this.onData(chunk, 'stdout');
114114
}
115115

116116
protected onStderr(chunk: string | Buffer) {
117-
this.onData(chunk, this.errBuffer, 'stderr');
117+
this.onData(chunk, 'stderr');
118118
}
119119

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

124-
const end = buffer.lastIndexOf('\n');
124+
const end = this[bufferName].lastIndexOf('\n');
125125
if (end !== -1) {
126-
const data = buffer.substring(0, end);
126+
const data = this[bufferName].substring(0, end);
127127
this.emit(event, data);
128128
this.handleData(data);
129-
buffer = buffer.substring(end + 1);
129+
this[bufferName] = this[bufferName].substring(end + 1);
130130
}
131131
}
132132

0 commit comments

Comments
 (0)