Skip to content

Commit 24e96b2

Browse files
oyydtargos
authored andcommitted
net: some scattered cleanup
This commit cleans up net module, including: 1. remove assigning `handle.readable` and `handle.writable` 2. documents `NODE_PENDING_PIPE_INSTANCES` enviroment variable 3. use constants for '0.0.0.0' and '::'. PR-URL: #24128 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 1b45534 commit 24e96b2

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

doc/api/cli.md

+5
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,11 @@ unless either the `--pending-deprecation` command line flag, or the
752752
are used to provide a kind of selective "early warning" mechanism that
753753
developers may leverage to detect deprecated API usage.
754754

755+
### `NODE_PENDING_PIPE_INSTANCES=instances`
756+
757+
Set the number of pending pipe instance handles when the pipe server is waiting
758+
for connections. This setting applies to Windows only.
759+
755760
### `NODE_PRESERVE_SYMLINKS=1`
756761
<!-- YAML
757762
added: v7.1.0

lib/internal/main/print_help.js

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const envVars = new Map([
2828
'of directories prefixed to the module search path' }],
2929
['NODE_PENDING_DEPRECATION', { helpText: 'set to 1 to emit pending ' +
3030
'deprecation warnings' }],
31+
['NODE_PENDING_PIPE_INSTANCES', { helpText: 'set the number of pending ' +
32+
'pipe instance handles on Windows' }],
3133
['NODE_PRESERVE_SYMLINKS', { helpText: 'set to 1 to preserve symbolic ' +
3234
'links when resolving and caching modules' }],
3335
['NODE_REDIRECT_WARNINGS', { helpText: 'write warnings to path instead ' +

lib/net.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ const {
9595
validateTimerDuration
9696
} = require('internal/timers');
9797

98+
const DEFAULT_IPV4_ADDR = '0.0.0.0';
99+
const DEFAULT_IPV6_ADDR = '::';
100+
98101
function noop() {}
99102

100103
function getFlags(ipv6Only) {
@@ -810,10 +813,10 @@ function internalConnect(
810813

811814
if (localAddress || localPort) {
812815
if (addressType === 4) {
813-
localAddress = localAddress || '0.0.0.0';
816+
localAddress = localAddress || DEFAULT_IPV4_ADDR;
814817
err = self._handle.bind(localAddress, localPort);
815818
} else { // addressType === 6
816-
localAddress = localAddress || '::';
819+
localAddress = localAddress || DEFAULT_IPV6_ADDR;
817820
err = self._handle.bind6(localAddress, localPort, flags);
818821
}
819822
debug('binding to localAddress: %s and localPort: %d (addressType: %d)',
@@ -1165,8 +1168,6 @@ function createServerHandle(address, port, addressType, fd, flags) {
11651168
if (err)
11661169
return err;
11671170

1168-
handle.readable = true;
1169-
handle.writable = true;
11701171
assert(!address && !port);
11711172
} else if (port === -1 && addressType === -1) {
11721173
handle = new Pipe(PipeConstants.SERVER);
@@ -1185,11 +1186,11 @@ function createServerHandle(address, port, addressType, fd, flags) {
11851186
debug('bind to', address || 'any');
11861187
if (!address) {
11871188
// Try binding to ipv6 first
1188-
err = handle.bind6('::', port, flags);
1189+
err = handle.bind6(DEFAULT_IPV6_ADDR, port, flags);
11891190
if (err) {
11901191
handle.close();
11911192
// Fallback to ipv4
1192-
return createServerHandle('0.0.0.0', port);
1193+
return createServerHandle(DEFAULT_IPV4_ADDR, port);
11931194
}
11941195
} else if (addressType === 6) {
11951196
err = handle.bind6(address, port, flags);
@@ -1220,14 +1221,14 @@ function setupListenHandle(address, port, addressType, backlog, fd, flags) {
12201221

12211222
// Try to bind to the unspecified IPv6 address, see if IPv6 is available
12221223
if (!address && typeof fd !== 'number') {
1223-
rval = createServerHandle('::', port, 6, fd, flags);
1224+
rval = createServerHandle(DEFAULT_IPV6_ADDR, port, 6, fd, flags);
12241225

12251226
if (typeof rval === 'number') {
12261227
rval = null;
1227-
address = '0.0.0.0';
1228+
address = DEFAULT_IPV4_ADDR;
12281229
addressType = 4;
12291230
} else {
1230-
address = '::';
1231+
address = DEFAULT_IPV6_ADDR;
12311232
addressType = 6;
12321233
}
12331234
}

0 commit comments

Comments
 (0)