Skip to content

Commit cd8b739

Browse files
committed
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 <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent d78d33d commit cd8b739

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
@@ -768,6 +768,11 @@ unless either the `--pending-deprecation` command line flag, or the
768768
are used to provide a kind of selective "early warning" mechanism that
769769
developers may leverage to detect deprecated API usage.
770770

771+
### `NODE_PENDING_PIPE_INSTANCES=instances`
772+
773+
Set the number of pending pipe instance handles when the pipe server is waiting
774+
for connections. This setting applies to Windows only.
775+
771776
### `NODE_PRESERVE_SYMLINKS=1`
772777
<!-- YAML
773778
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
@@ -96,6 +96,9 @@ let dns;
9696

9797
const { kTimeout } = require('internal/timers');
9898

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

101104
function getFlags(ipv6Only) {
@@ -789,10 +792,10 @@ function internalConnect(
789792

790793
if (localAddress || localPort) {
791794
if (addressType === 4) {
792-
localAddress = localAddress || '0.0.0.0';
795+
localAddress = localAddress || DEFAULT_IPV4_ADDR;
793796
err = self._handle.bind(localAddress, localPort);
794797
} else { // addressType === 6
795-
localAddress = localAddress || '::';
798+
localAddress = localAddress || DEFAULT_IPV6_ADDR;
796799
err = self._handle.bind6(localAddress, localPort, flags);
797800
}
798801
debug('binding to localAddress: %s and localPort: %d (addressType: %d)',
@@ -1145,8 +1148,6 @@ function createServerHandle(address, port, addressType, fd, flags) {
11451148
if (err)
11461149
return err;
11471150

1148-
handle.readable = true;
1149-
handle.writable = true;
11501151
assert(!address && !port);
11511152
} else if (port === -1 && addressType === -1) {
11521153
handle = new Pipe(PipeConstants.SERVER);
@@ -1165,11 +1166,11 @@ function createServerHandle(address, port, addressType, fd, flags) {
11651166
debug('bind to', address || 'any');
11661167
if (!address) {
11671168
// Try binding to ipv6 first
1168-
err = handle.bind6('::', port, flags);
1169+
err = handle.bind6(DEFAULT_IPV6_ADDR, port, flags);
11691170
if (err) {
11701171
handle.close();
11711172
// Fallback to ipv4
1172-
return createServerHandle('0.0.0.0', port);
1173+
return createServerHandle(DEFAULT_IPV4_ADDR, port);
11731174
}
11741175
} else if (addressType === 6) {
11751176
err = handle.bind6(address, port, flags);
@@ -1200,14 +1201,14 @@ function setupListenHandle(address, port, addressType, backlog, fd, flags) {
12001201

12011202
// Try to bind to the unspecified IPv6 address, see if IPv6 is available
12021203
if (!address && typeof fd !== 'number') {
1203-
rval = createServerHandle('::', port, 6, fd, flags);
1204+
rval = createServerHandle(DEFAULT_IPV6_ADDR, port, 6, fd, flags);
12041205

12051206
if (typeof rval === 'number') {
12061207
rval = null;
1207-
address = '0.0.0.0';
1208+
address = DEFAULT_IPV4_ADDR;
12081209
addressType = 4;
12091210
} else {
1210-
address = '::';
1211+
address = DEFAULT_IPV6_ADDR;
12111212
addressType = 6;
12121213
}
12131214
}

0 commit comments

Comments
 (0)