Skip to content

Commit

Permalink
net: some scattered cleanup
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
oyyd authored and targos committed Mar 27, 2019
1 parent 1b45534 commit 24e96b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,11 @@ unless either the `--pending-deprecation` command line flag, or the
are used to provide a kind of selective "early warning" mechanism that
developers may leverage to detect deprecated API usage.

### `NODE_PENDING_PIPE_INSTANCES=instances`

Set the number of pending pipe instance handles when the pipe server is waiting
for connections. This setting applies to Windows only.

### `NODE_PRESERVE_SYMLINKS=1`
<!-- YAML
added: v7.1.0
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/print_help.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const envVars = new Map([
'of directories prefixed to the module search path' }],
['NODE_PENDING_DEPRECATION', { helpText: 'set to 1 to emit pending ' +
'deprecation warnings' }],
['NODE_PENDING_PIPE_INSTANCES', { helpText: 'set the number of pending ' +
'pipe instance handles on Windows' }],
['NODE_PRESERVE_SYMLINKS', { helpText: 'set to 1 to preserve symbolic ' +
'links when resolving and caching modules' }],
['NODE_REDIRECT_WARNINGS', { helpText: 'write warnings to path instead ' +
Expand Down
19 changes: 10 additions & 9 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const {
validateTimerDuration
} = require('internal/timers');

const DEFAULT_IPV4_ADDR = '0.0.0.0';
const DEFAULT_IPV6_ADDR = '::';

function noop() {}

function getFlags(ipv6Only) {
Expand Down Expand Up @@ -810,10 +813,10 @@ function internalConnect(

if (localAddress || localPort) {
if (addressType === 4) {
localAddress = localAddress || '0.0.0.0';
localAddress = localAddress || DEFAULT_IPV4_ADDR;
err = self._handle.bind(localAddress, localPort);
} else { // addressType === 6
localAddress = localAddress || '::';
localAddress = localAddress || DEFAULT_IPV6_ADDR;
err = self._handle.bind6(localAddress, localPort, flags);
}
debug('binding to localAddress: %s and localPort: %d (addressType: %d)',
Expand Down Expand Up @@ -1165,8 +1168,6 @@ function createServerHandle(address, port, addressType, fd, flags) {
if (err)
return err;

handle.readable = true;
handle.writable = true;
assert(!address && !port);
} else if (port === -1 && addressType === -1) {
handle = new Pipe(PipeConstants.SERVER);
Expand All @@ -1185,11 +1186,11 @@ function createServerHandle(address, port, addressType, fd, flags) {
debug('bind to', address || 'any');
if (!address) {
// Try binding to ipv6 first
err = handle.bind6('::', port, flags);
err = handle.bind6(DEFAULT_IPV6_ADDR, port, flags);
if (err) {
handle.close();
// Fallback to ipv4
return createServerHandle('0.0.0.0', port);
return createServerHandle(DEFAULT_IPV4_ADDR, port);
}
} else if (addressType === 6) {
err = handle.bind6(address, port, flags);
Expand Down Expand Up @@ -1220,14 +1221,14 @@ function setupListenHandle(address, port, addressType, backlog, fd, flags) {

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

if (typeof rval === 'number') {
rval = null;
address = '0.0.0.0';
address = DEFAULT_IPV4_ADDR;
addressType = 4;
} else {
address = '::';
address = DEFAULT_IPV6_ADDR;
addressType = 6;
}
}
Expand Down

0 comments on commit 24e96b2

Please sign in to comment.