From d798da42d50e5e989b9e3f2e6ceda46c103ac11a Mon Sep 17 00:00:00 2001 From: theanarkh Date: Wed, 3 Apr 2024 21:37:12 +0800 Subject: [PATCH] src: add UV_PIPE_NO_TRUNCATE for bind in pipe_wrap.cc --- doc/api/net.md | 10 +++++----- src/pipe_wrap.cc | 11 ++++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/doc/api/net.md b/doc/api/net.md index c34bd0ced5b6e1..eb6c6dec0507fc 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -29,11 +29,11 @@ sockets on other operating systems. [`socket.connect()`][] take a `path` parameter to identify IPC endpoints. On Unix, the local domain is also known as the Unix domain. The path is a -file system pathname. It gets truncated to an OS-dependent length of -`sizeof(sockaddr_un.sun_path) - 1`. Typical values are 107 bytes on Linux and -103 bytes on macOS. If a Node.js API abstraction creates the Unix domain socket, -it will unlink the Unix domain socket as well. For example, -[`net.createServer()`][] may create a Unix domain socket and +file system pathname. It will throw an error when the length of pathname is +greater than the length of `sizeof(sockaddr_un.sun_path)`. Typical values are +107 bytes on Linux and 103 bytes on macOS. If a Node.js API abstraction creates +the Unix domain socket, it will unlink the Unix domain socket as well. For +example, [`net.createServer()`][] may create a Unix domain socket and [`server.close()`][] will unlink it. But if a user creates the Unix domain socket outside of these abstractions, the user will need to remove it. The same applies when a Node.js API creates a Unix domain socket but the program then diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 3f7cf26709e57f..359f99e79c484c 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -162,7 +162,8 @@ void PipeWrap::Bind(const FunctionCallbackInfo& args) { PipeWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); node::Utf8Value name(args.GetIsolate(), args[0]); - int err = uv_pipe_bind2(&wrap->handle_, *name, name.length(), 0); + int err = + uv_pipe_bind2(&wrap->handle_, *name, name.length(), UV_PIPE_NO_TRUNCATE); args.GetReturnValue().Set(err); } @@ -225,8 +226,12 @@ void PipeWrap::Connect(const FunctionCallbackInfo& args) { ConnectWrap* req_wrap = new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPECONNECTWRAP); - int err = req_wrap->Dispatch( - uv_pipe_connect2, &wrap->handle_, *name, name.length(), 0, AfterConnect); + int err = req_wrap->Dispatch(uv_pipe_connect2, + &wrap->handle_, + *name, + name.length(), + UV_PIPE_NO_TRUNCATE, + AfterConnect); if (err) { delete req_wrap; } else {