Skip to content

Commit b5f1ce4

Browse files
committed
fix: throw in (set|get)ters when constant == null
1 parent afd62f3 commit b5f1ce4

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ module.exports.getKeepAliveProbes = function getKeepAliveProbes(socket) {
217217
/**
218218
* Sets the TCP_USER_TIMEOUT value for specified socket.
219219
*
220-
* Note: The msec will be rounded towards the closest integer
220+
* Notes:
221+
* * This method is only supported on `linux`, will throw on `darwin` and `freebsd`.
222+
* * The msec will be rounded towards the closest integer.
223+
*
221224
*
222225
* @since v1.4.0
223226
* @param {Net.Socket} socket to set the value for
@@ -229,19 +232,21 @@ module.exports.getKeepAliveProbes = function getKeepAliveProbes(socket) {
229232
* NetKeepAlive.setUserTimeout(s, 30000)
230233
*
231234
* @throws {AssertionError} setUserTimeout requires two arguments
235+
* @throws {AssertionError} setUserTimeout called on unsupported platform
232236
* @throws {AssertionError} setUserTimeout expects an instance of socket as its first argument
233237
* @throws {AssertionError} setUserTimeout requires msec to be a Number
234238
* @throws {ErrnoException|Error} Unexpected error
235239
*/
236-
module.exports.setUserTimeout = function setUserTimeout(
237-
socket,
238-
msecs
239-
) {
240+
module.exports.setUserTimeout = function setUserTimeout(socket, msecs) {
240241
Assert.strictEqual(
241242
arguments.length,
242243
2,
243244
'setUserTimeout requires two arguments'
244245
)
246+
Assert(
247+
Constants.TCP_USER_TIMEOUT != null,
248+
'setUserTimeout called on unsupported platform'
249+
)
245250
Assert(
246251
_isSocket(socket),
247252
'setUserTimeout expects an instance of socket as its first argument'
@@ -269,6 +274,8 @@ module.exports.setUserTimeout = function setUserTimeout(
269274
/**
270275
* Returns the TCP_USER_TIMEOUT value for specified socket.
271276
*
277+
* Note: This method is only supported on `linux`, will throw on `darwin` and `freebsd`.
278+
*
272279
* @since v1.4.0
273280
* @param {Net.Socket} socket to check the value for
274281
*
@@ -278,6 +285,7 @@ module.exports.setUserTimeout = function setUserTimeout(
278285
* NetKeepAlive.getUserTimeout(s) // returns 30000 based on setter example
279286
*
280287
* @throws {AssertionError} getUserTimeout requires one arguments
288+
* @throws {AssertionError} getUserTimeout called on unsupported platform
281289
* @throws {AssertionError} getUserTimeout expects an instance of socket as its first argument
282290
* @throws {ErrnoException|Error} Unexpected error
283291
*/
@@ -287,6 +295,10 @@ module.exports.getUserTimeout = function getUserTimeout(socket) {
287295
1,
288296
'getUserTimeout requires one arguments'
289297
)
298+
Assert(
299+
Constants.TCP_USER_TIMEOUT != null,
300+
'getUserTimeout called on unsupported platform'
301+
)
290302
Assert(
291303
_isSocket(socket),
292304
'getUserTimeout expects an instance of socket as its first argument'

0 commit comments

Comments
 (0)