Skip to content
Permalink
Browse files

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>
  • Loading branch information...
oyyd committed Mar 13, 2019
1 parent d78d33d commit cd8b7391dcb1d889b7bf81f4bdb8f7990a6ad475
Showing with 17 additions and 9 deletions.
  1. +5 −0 doc/api/cli.md
  2. +2 −0 lib/internal/main/print_help.js
  3. +10 −9 lib/net.js
@@ -768,6 +768,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
@@ -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 ' +
@@ -96,6 +96,9 @@ let dns;

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

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

function noop() {}

function getFlags(ipv6Only) {
@@ -789,10 +792,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)',
@@ -1145,8 +1148,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);
@@ -1165,11 +1166,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);
@@ -1200,14 +1201,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;
}
}

0 comments on commit cd8b739

Please sign in to comment.
You can’t perform that action at this time.