Skip to content

Commit

Permalink
src: enable writev for pipe handles on Unix
Browse files Browse the repository at this point in the history
This commit enables writev for Unix Domain Sockets on supported
platforms thus enabling cork/uncork functionality for them and
improving IPC performance.

Fixes: #5095
PR-URL: #10677
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
aqrln authored and italoacasas committed Jan 27, 2017
1 parent 06a1e9e commit b89d848
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/pipe_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
46 changes: 46 additions & 0 deletions test/parallel/test-pipe-writev.js
Original file line number Diff line number Diff line change
@@ -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();
});
});

0 comments on commit b89d848

Please sign in to comment.