Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Keep-alive probe interval and probe limit for keep-alives on sockets #2239

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions doc/api/net.markdown
Expand Up @@ -339,14 +339,17 @@ Disables the Nagle algorithm. By default TCP connections use the Nagle
algorithm, they buffer data before sending it off. Setting `noDelay` will algorithm, they buffer data before sending it off. Setting `noDelay` will
immediately fire off data each time `socket.write()` is called. immediately fire off data each time `socket.write()` is called.


#### socket.setKeepAlive(enable=false, [initialDelay]) #### socket.setKeepAlive(enable=false, [initialDelay], [probeInterval], [failureCount])


Enable/disable keep-alive functionality, and optionally set the initial Enable/disable keep-alive functionality, and optionally override default
delay before the first keepalive probe is sent on an idle socket. keep-alive options. Set `initialDelay` (in milliseconds) to set the delay
Set `initialDelay` (in milliseconds) to set the delay between the last between the last data packet received and the first keepalive probe. Set
data packet received and the first keepalive probe. Setting 0 for `probeInterval` (in milliseconds) to set the interval between the keep-
initialDelay will leave the value unchanged from the default alive probes sent after the initial probe. Set `failureCount` to set the
(or previous) setting. maximum number of probes that can fail before the OS closes the connection.
probeInterval and failureCount do not work on Windows OS. Setting 0 for
initialDelay, probeInterval, or failureCount will leave the value unchanged
from the default (or previous) setting.


#### socket.address() #### socket.address()


Expand Down
4 changes: 2 additions & 2 deletions lib/net.js
Expand Up @@ -158,9 +158,9 @@ Socket.prototype.setNoDelay = function() {
}; };




Socket.prototype.setKeepAlive = function(setting, msecs) { Socket.prototype.setKeepAlive = function(setting, msecs, interval, count) {
if (this._handle && this._handle.setKeepAlive) if (this._handle && this._handle.setKeepAlive)
this._handle.setKeepAlive(setting, ~~(msecs / 1000)); this._handle.setKeepAlive(setting, ~~(msecs / 1000), ~~(interval / 1000), count);
}; };




Expand Down
4 changes: 3 additions & 1 deletion src/tcp_wrap.cc
Expand Up @@ -267,8 +267,10 @@ Handle<Value> TCPWrap::SetKeepAlive(const Arguments& args) {


int enable = args[0]->Int32Value(); int enable = args[0]->Int32Value();
unsigned int delay = args[1]->Uint32Value(); unsigned int delay = args[1]->Uint32Value();
unsigned int interval = args[2]->Uint32Value();
unsigned int count = args[3]->Uint32Value();


int r = uv_tcp_keepalive(&wrap->handle_, enable, delay); int r = uv_tcp_keepalive(&wrap->handle_, enable, delay, interval, count);
if (r) if (r)
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(uv_default_loop()));


Expand Down