GeezerVison is showing github.com — src: add UV_PIPE_NO_TRUNCATE for bind in pipe_wrap.cc · nodejs/node@7588467
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/net.md +5-5Lines changed: 5 additions & 5 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -37,11 +37,11 @@ sockets on other operating systems. | 37 | 37 | [`socket.connect()`][] take a `path` parameter to identify IPC endpoints. | 38 | 38 |
| 39 | 39 | On Unix, the local domain is also known as the Unix domain. The path is a | 40 | | -file system pathname. It gets truncated to an OS-dependent length of | 41 | | -`sizeof(sockaddr_un.sun_path) - 1`. Typical values are 107 bytes on Linux and | 42 | | -103 bytes on macOS. If a Node.js API abstraction creates the Unix domain socket, | 43 | | -it will unlink the Unix domain socket as well. For example, | 44 | | -[`net.createServer()`][] may create a Unix domain socket and | | 40 | +file system pathname. It will throw an error when the length of pathname is | | 41 | +greater than the length of `sizeof(sockaddr_un.sun_path)`. Typical values are | | 42 | +107 bytes on Linux and 103 bytes on macOS. If a Node.js API abstraction creates | | 43 | +the Unix domain socket, it will unlink the Unix domain socket as well. For | | 44 | +example, [`net.createServer()`][] may create a Unix domain socket and | 45 | 45 | [`server.close()`][] will unlink it. But if a user creates the Unix domain | 46 | 46 | socket outside of these abstractions, the user will need to remove it. The same | 47 | 47 | applies when a Node.js API creates a Unix domain socket but the program then | |
Collapse file Copy file name to clipboardExpand all lines: src/pipe_wrap.cc +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -162,7 +162,8 @@ void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) { | 162 | 162 | PipeWrap* wrap; | 163 | 163 | ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | 164 | 164 | node::Utf8Value name(args.GetIsolate(), args[0]); | 165 | | - int err = uv_pipe_bind2(&wrap->handle_, *name, name.length(), 0); | | 165 | + int err = | | 166 | + uv_pipe_bind2(&wrap->handle_, *name, name.length(), UV_PIPE_NO_TRUNCATE); | 166 | 167 | args.GetReturnValue().Set(err); | 167 | 168 | } | 168 | 169 |
| @@ -225,8 +226,12 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) { | 225 | 226 |
| 226 | 227 | ConnectWrap* req_wrap = | 227 | 228 | new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPECONNECTWRAP); | 228 | | - int err = req_wrap->Dispatch( | 229 | | - uv_pipe_connect2, &wrap->handle_, *name, name.length(), 0, AfterConnect); | | 229 | + int err = req_wrap->Dispatch(uv_pipe_connect2, | | 230 | + &wrap->handle_, | | 231 | + *name, | | 232 | + name.length(), | | 233 | + UV_PIPE_NO_TRUNCATE, | | 234 | + AfterConnect); | 230 | 235 | if (err) { | 231 | 236 | delete req_wrap; | 232 | 237 | } else { | |
Collapse file Copy file name to clipboard +36Lines changed: 36 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const common = require('../common'); | | 3 | +const assert = require('assert'); | | 4 | +const net = require('net'); | | 5 | +const fs = require('fs'); | | 6 | +const tmpdir = require('../common/tmpdir'); | | 7 | +tmpdir.refresh(); | | 8 | + | | 9 | +// Test UV_PIPE_NO_TRUNCATE | | 10 | + | | 11 | +// See pipe_overlong_path in https://github.com/libuv/libuv/blob/master/test/test-pipe-bind-error.c | | 12 | +if (common.isWindows) { | | 13 | + common.skip('UV_PIPE_NO_TRUNCATE is not supported on window'); | | 14 | +} | | 15 | + | | 16 | +// See https://github.com/libuv/libuv/issues/4231 | | 17 | +const pipePath = `${tmpdir.path}/${'x'.repeat(10000)}.sock`; | | 18 | + | | 19 | +const server = net.createServer() | | 20 | + .listen(pipePath) | | 21 | + // It may work on some operating systems | | 22 | + .on('listening', () => { | | 23 | + // The socket file must exsit | | 24 | + assert.ok(fs.existsSync(pipePath)); | | 25 | + const socket = net.connect(pipePath, common.mustCall(() => { | | 26 | + socket.destroy(); | | 27 | + server.close(); | | 28 | + })); | | 29 | + }) | | 30 | + .on('error', (error) => { | | 31 | + assert.ok(error.code === 'EINVAL', error.message); | | 32 | + net.connect(pipePath) | | 33 | + .on('error', common.mustCall((error) => { | | 34 | + assert.ok(error.code === 'EINVAL', error.message); | | 35 | + })); | | 36 | + }); |
|