net: fix setting of value in 'setDefaultAutoSelectFamilyAttemptTimeout'

Document describes that the value have to be 10 if passed value to
`setDefaultAutoSelectFamilyAttemptTimeout` is less than 10.
So need to use 10 for 'if' statement and fix typo in document.

Refs: https://github.com/nodejs/node/blob/main/doc/api/net.md#netsetdefaultautoselectfamilyattempttimeoutvalue
PR-URL: https://github.com/nodejs/node/pull/47012
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
This commit is contained in:
Deokjin Kim 2023-03-11 00:07:55 +09:00 committed by GitHub
parent 72e971ee2e
commit b0d31bb854
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -1661,7 +1661,7 @@ added: REPLACEME
Sets the default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][].
* `value` {number} The new default value, which must be a positive number. If the number is less than `10`,
the value `10` is used insted The initial default value is `250`.
the value `10` is used instead. The initial default value is `250`.
## `net.isIP(input)`

View File

@ -247,7 +247,7 @@ function getDefaultAutoSelectFamilyAttemptTimeout() {
function setDefaultAutoSelectFamilyAttemptTimeout(value) {
validateInt32(value, 'value', 1);
if (value < 1) {
if (value < 10) {
value = 10;
}

View File

@ -18,3 +18,10 @@ for (const autoSelectFamilyAttemptTimeout of [-10, 0]) {
net.setDefaultAutoSelectFamilyAttemptTimeout(autoSelectFamilyAttemptTimeout);
}, { code: 'ERR_OUT_OF_RANGE' });
}
// Check the default value of autoSelectFamilyAttemptTimeout is 10
// if passed number is less than 10
for (const autoSelectFamilyAttemptTimeout of [1, 9]) {
net.setDefaultAutoSelectFamilyAttemptTimeout(autoSelectFamilyAttemptTimeout);
assert.strictEqual(net.getDefaultAutoSelectFamilyAttemptTimeout(), 10);
}