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
Examples
require('net-keepalive')
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
getKeepAliveInterval requires one arguments
getKeepAliveInterval expects an instance of socket as its first argument
Unexpected error
interval (ms) in-between probes
Example
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
getKeepAliveProbes requires one arguments
getKeepAliveProbes expects an instance of socket as its first argument
Unexpected error
number of probes to send
Example
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
getUserTimeout requires one arguments
getUserTimeout called on unsupported platform
getUserTimeout expects an instance of socket as its first argument
Unexpected error
msecs to wait for unacknowledged data before closing the connection
Example
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
setKeepAliveInterval requires two arguments
setKeepAliveInterval expects an instance of socket as its first argument
setKeepAliveInterval requires msec to be a Number
Unexpected error
true
on success
Example
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
setKeepAliveProbes requires two arguments
setKeepAliveProbes expects an instance of socket as its first argument
setKeepAliveProbes requires cnt to be a Number
Unexpected error
true
on success
Example
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
anddarwin
, will throw onfreebsd
. - 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:
setUserTimeout requires two arguments
setUserTimeout called on unsupported platform
setUserTimeout expects an instance of socket as its first argument
setUserTimeout requires msec to be a Number
Unexpected error
true
on success
Example
NetKeepAlive.setUserTimeout(s, 30000)