Browse Source

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>
v6.x
Alexey Orlenko 8 years ago
committed by Myles Borins
parent
commit
4358c6096c
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 4
      src/pipe_wrap.cc
  2. 46
      test/parallel/test-pipe-writev.js

4
src/pipe_wrap.cc

@ -53,7 +53,11 @@ void PipeWrap::Initialize(Local<Object> target,
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef);
#ifdef _WIN32
StreamWrap::AddMethods(env, t);
#else
StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev);
#endif
env->SetProtoMethod(t, "bind", Bind);
env->SetProtoMethod(t, "listen", Listen);

46
test/parallel/test-pipe-writev.js

@ -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…
Cancel
Save