child_process: fix stdio sockets creation

`readable` and `writable` properties can be passed directly to the
`net.Socket` constructor. This change also avoids an unnecessary call
to `read(0)` on the `stdin` socket. This behavior was disclosed when
trying to merge `libuv@1.19.0` and specifically this commit:
fd049399aa.

PR-URL: https://github.com/nodejs/node/pull/18701
Refs: https://github.com/libuv/libuv/pull/1655
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
pull/18257/merge
Santiago Gimeno 2018-02-06 18:31:14 +01:00 committed by Ruben Bridgewater
parent f25104e136
commit b74a6da5d0
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 2 additions and 12 deletions

View File

@ -238,17 +238,7 @@ function flushStdio(subprocess) {
function createSocket(pipe, readable) {
var s = new net.Socket({ handle: pipe });
if (readable) {
s.writable = false;
s.readable = true;
} else {
s.writable = true;
s.readable = false;
}
return s;
return net.Socket({ handle: pipe, readable, writable: !readable });
}

View File

@ -78,7 +78,7 @@ function onexit() {
// Usually it is just one event, but it can be more.
assert.ok(ioEvents >= 3, `at least 3 stdout io events, got ${ioEvents}`);
checkInvocations(pipe1, { init: 1, before: 2, after: 2 },
checkInvocations(pipe1, { init: 1, before: 1, after: 1 },
'pipe wrap when sleep.spawn was called');
checkInvocations(pipe2, { init: 1, before: ioEvents, after: ioEvents },
'pipe wrap when sleep.spawn was called');