Skip to content

Commit b89d848

Browse files
aqrlnitaloacasas
authored andcommitted
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: #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]>
1 parent 06a1e9e commit b89d848

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/pipe_wrap.cc

+4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ void PipeWrap::Initialize(Local<Object> target,
5353
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
5454
env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef);
5555

56+
#ifdef _WIN32
5657
StreamWrap::AddMethods(env, t);
58+
#else
59+
StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev);
60+
#endif
5761

5862
env->SetProtoMethod(t, "bind", Bind);
5963
env->SetProtoMethod(t, "listen", Listen);

test/parallel/test-pipe-writev.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const net = require('net');
6+
7+
if (common.isWindows) {
8+
common.skip('Unix-specific test');
9+
return;
10+
}
11+
12+
common.refreshTmpDir();
13+
14+
const server = net.createServer((connection) => {
15+
connection.on('error', (err) => {
16+
throw err;
17+
});
18+
19+
const writev = connection._writev.bind(connection);
20+
connection._writev = common.mustCall(writev);
21+
22+
connection.cork();
23+
connection.write('pi');
24+
connection.write('ng');
25+
connection.end();
26+
});
27+
28+
server.on('error', (err) => {
29+
throw err;
30+
});
31+
32+
server.listen(common.PIPE, () => {
33+
const client = net.connect(common.PIPE);
34+
35+
client.on('error', (err) => {
36+
throw err;
37+
});
38+
39+
client.on('data', common.mustCall((data) => {
40+
assert.strictEqual(data.toString(), 'ping');
41+
}));
42+
43+
client.on('end', () => {
44+
server.close();
45+
});
46+
});

0 commit comments

Comments
 (0)