src: enable writev for pipe handles on Unix
This commit enables writev for Unix Domain Sockets on supported platforms thus enabling cork/uncork functionality for them and improving IPC performance. Fixes: https://github.com/nodejs/node/issues/5095 PR-URL: https://github.com/nodejs/node/pull/10677 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
0674789f36
commit
d85d120593
@ -53,7 +53,11 @@ void PipeWrap::Initialize(Local<Object> target,
|
|||||||
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
|
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
|
||||||
env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef);
|
env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
StreamWrap::AddMethods(env, t);
|
StreamWrap::AddMethods(env, t);
|
||||||
|
#else
|
||||||
|
StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev);
|
||||||
|
#endif
|
||||||
|
|
||||||
env->SetProtoMethod(t, "bind", Bind);
|
env->SetProtoMethod(t, "bind", Bind);
|
||||||
env->SetProtoMethod(t, "listen", Listen);
|
env->SetProtoMethod(t, "listen", Listen);
|
||||||
|
46
test/parallel/test-pipe-writev.js
Normal file
46
test/parallel/test-pipe-writev.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const common = require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const net = require('net');
|
||||||
|
|
||||||
|
if (common.isWindows) {
|
||||||
|
common.skip('Unix-specific test');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
common.refreshTmpDir();
|
||||||
|
|
||||||
|
const server = net.createServer((connection) => {
|
||||||
|
connection.on('error', (err) => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
const writev = connection._writev.bind(connection);
|
||||||
|
connection._writev = common.mustCall(writev);
|
||||||
|
|
||||||
|
connection.cork();
|
||||||
|
connection.write('pi');
|
||||||
|
connection.write('ng');
|
||||||
|
connection.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
server.on('error', (err) => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(common.PIPE, () => {
|
||||||
|
const client = net.connect(common.PIPE);
|
||||||
|
|
||||||
|
client.on('error', (err) => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('data', common.mustCall((data) => {
|
||||||
|
assert.strictEqual(data.toString(), 'ping');
|
||||||
|
}));
|
||||||
|
|
||||||
|
client.on('end', () => {
|
||||||
|
server.close();
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user