From 7c7f5c88690f049cf76fb562f1b3646c24a38ff3 Mon Sep 17 00:00:00 2001 From: rickyes Date: Thu, 21 May 2020 22:41:13 +0800 Subject: [PATCH] net: refactor check for Windows PR-URL: https://github.com/nodejs/node/pull/33497 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Richard Lau Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater --- lib/net.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/net.js b/lib/net.js index fa6574c183e48e..9552b24e5a3cb3 100644 --- a/lib/net.js +++ b/lib/net.js @@ -119,6 +119,8 @@ const { kTimeout } = require('internal/timers'); const DEFAULT_IPV4_ADDR = '0.0.0.0'; const DEFAULT_IPV6_ADDR = '::'; +const isWindows = process.platform === 'win32'; + function noop() {} function getFlags(ipv6Only) { @@ -336,8 +338,7 @@ function Socket(options) { this[async_id_symbol] = this._handle.getAsyncId(); if ((fd === 1 || fd === 2) && - (this._handle instanceof Pipe) && - process.platform === 'win32') { + (this._handle instanceof Pipe) && isWindows) { // Make stdout and stderr blocking on Windows err = this._handle.setBlocking(true); if (err) @@ -1028,7 +1029,7 @@ function lookupAndConnect(self, options) { hints: options.hints || 0 }; - if (process.platform !== 'win32' && + if (!isWindows && dnsopts.family !== 4 && dnsopts.family !== 6 && dnsopts.hints === 0) { @@ -1227,7 +1228,7 @@ function createServerHandle(address, port, addressType, fd, flags) { assert(!address && !port); } else if (port === -1 && addressType === -1) { handle = new Pipe(PipeConstants.SERVER); - if (process.platform === 'win32') { + if (isWindows) { const instances = parseInt(process.env.NODE_PENDING_PIPE_INSTANCES); if (!NumberIsNaN(instances)) { handle.setPendingInstances(instances); @@ -1711,7 +1712,7 @@ Server.prototype.unref = function() { let _setSimultaneousAccepts; let warnSimultaneousAccepts = true; -if (process.platform === 'win32') { +if (isWindows) { let simultaneousAccepts; _setSimultaneousAccepts = function(handle) {