Skip to content

Commit 711344e

Browse files
Fix stdin
1 parent ee2caa7 commit 711344e

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"build": "tsc",
77
"install": "npm run build",
8-
"test": "npm run build && webpack && node build/main.js"
8+
"test": "npm run build && webpack && (echo bar | node build/main.js)"
99
},
1010
"author": "Will Fancher",
1111
"dependencies": {

example/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class JSaddleDevice implements Device {
99

1010
configureFileSystem({ "/jsaddle": new JSaddleDevice() }, (err, fs) => {
1111
console.log(err);
12-
let buf = Buffer.from("hi\n");
13-
fs.write(1, buf, 0, buf.length, null, () => {});
12+
let buf = Buffer.from("foo\n");
13+
fs.write(1, buf, 0, buf.length, null, () => {
14+
fs.read(0, buf, 0, 4, null, (err, n, buf) => {
15+
console.log({ err: err, n: n, buf: buf.toString() });
16+
});
17+
});
1418
});

example/webpack.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ module.exports = {
1212
resolve: {
1313
// Using file:../kernel in package.json requires this
1414
symlinks: false
15+
},
16+
node: {
17+
process: false
1518
}
1619
};

kernel/src/stdio_handles.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ if (process && !(process as any).browser) {
7979

8080
onData(buf: Buffer): void {
8181
const reqs = this.requests;
82-
this.requests = <[Request]> [];
8382
let nextBuf: Buffer | null = null;
84-
for (const req of reqs) {
83+
let req: Request;
84+
while (req = this.requests.shift()) {
8585
if (buf.length > req.length) {
8686
nextBuf = buf.slice(req.length);
8787
buf = buf.slice(0, req.length);
@@ -92,6 +92,9 @@ if (process && !(process as any).browser) {
9292
const copied = buf.copy(req.buffer, req.offset);
9393
req.cb(undefined, copied, req.buffer);
9494

95+
if (!nextBuf || nextBuf.length == 0) {
96+
break;
97+
}
9598
buf = nextBuf;
9699
}
97100

0 commit comments

Comments
 (0)