Skip to content

Commit a597cb8

Browse files
ggoodmanruyadorno
authored andcommitted
src: port Pipe to uv_pipe_bind2, uv_pipe_connect2
The introduction of the uv_pipe_bind2 and uv_pipe_connect2 methods in libuv v1.46.0 changed the behaviour of uv_pipe_bind and uv_pipe_connect. This broke the ability to connect to abstract domain sockets on linux. This change ports PipeWrap to use the new uv_pipe_bind2 and uv_pipe_connect2 methods to restore abstract domain socket support. Fixes: #49656 Refs: libuv/libuv#4030 PR-URL: #49667 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b30754a commit a597cb8

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

src/pipe_wrap.cc

+7-22
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ MaybeLocal<Object> PipeWrap::Instantiate(Environment* env,
6262
constructor->NewInstance(env->context(), 1, &type_value));
6363
}
6464

65-
6665
void PipeWrap::Initialize(Local<Object> target,
6766
Local<Value> unused,
6867
Local<Context> context,
@@ -71,8 +70,7 @@ void PipeWrap::Initialize(Local<Object> target,
7170
Isolate* isolate = env->isolate();
7271

7372
Local<FunctionTemplate> t = NewFunctionTemplate(isolate, New);
74-
t->InstanceTemplate()
75-
->SetInternalFieldCount(StreamBase::kInternalFieldCount);
73+
t->InstanceTemplate()->SetInternalFieldCount(StreamBase::kInternalFieldCount);
7674

7775
t->Inherit(LibuvStreamWrap::GetConstructorTemplate(env));
7876

@@ -102,9 +100,7 @@ void PipeWrap::Initialize(Local<Object> target,
102100
NODE_DEFINE_CONSTANT(constants, IPC);
103101
NODE_DEFINE_CONSTANT(constants, UV_READABLE);
104102
NODE_DEFINE_CONSTANT(constants, UV_WRITABLE);
105-
target->Set(context,
106-
env->constants_string(),
107-
constants).Check();
103+
target->Set(context, env->constants_string(), constants).Check();
108104
}
109105

110106
void PipeWrap::RegisterExternalReferences(ExternalReferenceRegistry* registry) {
@@ -152,7 +148,6 @@ void PipeWrap::New(const FunctionCallbackInfo<Value>& args) {
152148
new PipeWrap(env, args.This(), provider, ipc);
153149
}
154150

155-
156151
PipeWrap::PipeWrap(Environment* env,
157152
Local<Object> object,
158153
ProviderType provider,
@@ -163,16 +158,14 @@ PipeWrap::PipeWrap(Environment* env,
163158
// Suggestion: uv_pipe_init() returns void.
164159
}
165160

166-
167161
void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
168162
PipeWrap* wrap;
169163
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
170164
node::Utf8Value name(args.GetIsolate(), args[0]);
171-
int err = uv_pipe_bind(&wrap->handle_, *name);
165+
int err = uv_pipe_bind2(&wrap->handle_, *name, name.length(), 0);
172166
args.GetReturnValue().Set(err);
173167
}
174168

175-
176169
#ifdef _WIN32
177170
void PipeWrap::SetPendingInstances(const FunctionCallbackInfo<Value>& args) {
178171
PipeWrap* wrap;
@@ -183,7 +176,6 @@ void PipeWrap::SetPendingInstances(const FunctionCallbackInfo<Value>& args) {
183176
}
184177
#endif
185178

186-
187179
void PipeWrap::Fchmod(const v8::FunctionCallbackInfo<v8::Value>& args) {
188180
PipeWrap* wrap;
189181
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
@@ -193,20 +185,17 @@ void PipeWrap::Fchmod(const v8::FunctionCallbackInfo<v8::Value>& args) {
193185
args.GetReturnValue().Set(err);
194186
}
195187

196-
197188
void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
198189
PipeWrap* wrap;
199190
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
200191
Environment* env = wrap->env();
201192
int backlog;
202193
if (!args[0]->Int32Value(env->context()).To(&backlog)) return;
203-
int err = uv_listen(reinterpret_cast<uv_stream_t*>(&wrap->handle_),
204-
backlog,
205-
OnConnection);
194+
int err = uv_listen(
195+
reinterpret_cast<uv_stream_t*>(&wrap->handle_), backlog, OnConnection);
206196
args.GetReturnValue().Set(err);
207197
}
208198

209-
210199
void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) {
211200
Environment* env = Environment::GetCurrent(args);
212201

@@ -222,7 +211,6 @@ void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) {
222211
args.GetReturnValue().Set(err);
223212
}
224213

225-
226214
void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
227215
Environment* env = Environment::GetCurrent(args);
228216

@@ -237,10 +225,8 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
237225

238226
ConnectWrap* req_wrap =
239227
new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPECONNECTWRAP);
240-
req_wrap->Dispatch(uv_pipe_connect,
241-
&wrap->handle_,
242-
*name,
243-
AfterConnect);
228+
req_wrap->Dispatch(
229+
uv_pipe_connect2, &wrap->handle_, *name, name.length(), 0, AfterConnect);
244230

245231
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE2(net, native),
246232
"connect",
@@ -251,7 +237,6 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
251237
args.GetReturnValue().Set(0); // uv_pipe_connect() doesn't return errors.
252238
}
253239

254-
255240
} // namespace node
256241

257242
NODE_BINDING_CONTEXT_AWARE_INTERNAL(pipe_wrap, node::PipeWrap::Initialize)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
5+
6+
if (!common.isLinux) common.skip();
7+
8+
const server = http.createServer(
9+
common.mustCall((req, res) => {
10+
res.end('ok');
11+
})
12+
);
13+
14+
server.listen(
15+
'\0abstract',
16+
common.mustCall(() => {
17+
http.get(
18+
{
19+
socketPath: server.address(),
20+
},
21+
common.mustCall((res) => {
22+
assert.strictEqual(res.statusCode, 200);
23+
server.close();
24+
})
25+
);
26+
})
27+
);

0 commit comments

Comments
 (0)