Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: some scattered cleanup #24128

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -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) {
Expand Down Expand Up @@ -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)',
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand Down