Module

net-keepalive

The Missing (TCP_KEEPINTVL and TCP_KEEPCNT) SO_KEEPALIVE socket option setters and getters for Node using ffi-rs module.

Note: For methods provided by this module to work you must enable SO_KEEPALIVE and set the TCP_KEEPIDLE options for socket using Net.Socket-s built in method socket.setKeepAlive([enable][, initialDelay]) !

Since:
  • v0.1.0
Author:

View Source index.js, line 1

Examples

CommonJS

require('net-keepalive')

ES Modules

import * as NetKeepalive from 'net-keepalive'

Methods

# static getKeepAliveInterval(socket) → {number}

Returns the TCP_KEEPINTVL value for specified socket.

Returns the TCP_KEEPINTVL value for specified socket.

Parameters:
Name Type Description
socket Net.Socket

to check the value for

Since:
  • v1.1.0

View Source index.js, line 109

getKeepAliveInterval requires one arguments

AssertionError

getKeepAliveInterval expects an instance of socket as its first argument

AssertionError

Unexpected error

ErrnoException | Error

interval (ms) in-between probes

number
Example

Get the current interval in-between probes for socket s

NetKeepAlive.getKeepAliveInterval(s) // returns 1000 based on setter example

# static getKeepAliveProbes(socket) → {number}

Returns the TCP_KEEPCNT value for specified socket.

Returns the TCP_KEEPCNT value for specified socket.

Parameters:
Name Type Description
socket Net.Socket

to check the value for

Since:
  • v1.1.0

View Source index.js, line 214

getKeepAliveProbes requires one arguments

AssertionError

getKeepAliveProbes expects an instance of socket as its first argument

AssertionError

Unexpected error

ErrnoException | Error

number of probes to send

number
Example

Get the current number of probes to send for socket s

NetKeepAlive.getKeepAliveProbes(s) // returns 1 based on setter example

# static getUserTimeout(socket) → {number}

Returns the TCP_USER_TIMEOUT value for specified socket.

Returns the TCP_USER_TIMEOUT value for specified socket.

Note: This method is only supported on linux, will throw on darwin and freebsd.

Parameters:
Name Type Description
socket Net.Socket

to check the value for

Since:
  • v1.4.0

View Source index.js, line 333

getUserTimeout requires one arguments

AssertionError

getUserTimeout called on unsupported platform

AssertionError

getUserTimeout expects an instance of socket as its first argument

AssertionError

Unexpected error

ErrnoException | Error

msecs to wait for unacknowledged data before closing the connection

number
Example

Get the current user timeout for socket s

NetKeepAlive.getUserTimeout(s) // returns 30000 based on setter example

# static setKeepAliveInterval(socket, msecs) → {boolean}

Sets the TCP_KEEPINTVL value for specified socket.

Sets the TCP_KEEPINTVL value for specified socket.

Note: The msec will be rounded towards the closest integer

Parameters:
Name Type Description
socket Net.Socket

to set the value for

msecs number

to wait in-between probes

Since:
  • v0.1.0

View Source index.js, line 57

setKeepAliveInterval requires two arguments

AssertionError

setKeepAliveInterval expects an instance of socket as its first argument

AssertionError

setKeepAliveInterval requires msec to be a Number

AssertionError

Unexpected error

ErrnoException | Error

true on success

boolean
Example

Set interval in-between probes to 1 second (1000 milliseconds) for socket s

NetKeepAlive.setKeepAliveInterval(s, 1000)

# static setKeepAliveProbes(socket, cnt) → {boolean}

Sets the TCP_KEEPCNT value for specified socket.

Sets the TCP_KEEPCNT value for specified socket.

Parameters:
Name Type Description
socket Net.Socket

to set the value for

cnt number

number of probes to send

Since:
  • v0.1.0

View Source index.js, line 165

setKeepAliveProbes requires two arguments

AssertionError

setKeepAliveProbes expects an instance of socket as its first argument

AssertionError

setKeepAliveProbes requires cnt to be a Number

AssertionError

Unexpected error

ErrnoException | Error

true on success

boolean
Example

Set number of probes to send to 1 for socket s

NetKeepAlive.setKeepAliveProbes(s, 1)

# static setUserTimeout(socket, msecs) → {boolean}

Sets the TCP_USER_TIMEOUT (TCP_RXT_CONNDROPTIME on darwin) value for specified socket.

Sets the TCP_USER_TIMEOUT (TCP_RXT_CONNDROPTIME on darwin) value for specified socket.

Notes:

  • This method is only supported on linux and darwin, will throw on freebsd.
  • The msec will be rounded towards the closest integer.
  • When used with the TCP keepalive options, will override them.
Parameters:
Name Type Description
socket Net.Socket

to set the value for

msecs number

to wait for unacknowledged data before closing the connection

Since:
  • v1.4.0
See:

View Source index.js, line 277

setUserTimeout requires two arguments

AssertionError

setUserTimeout called on unsupported platform

AssertionError

setUserTimeout expects an instance of socket as its first argument

AssertionError

setUserTimeout requires msec to be a Number

AssertionError

Unexpected error

ErrnoException | Error

true on success

boolean
Example

Set user timeout to 30 seconds (30000 milliseconds) for socket s

NetKeepAlive.setUserTimeout(s, 30000)