Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added interval and count options to setKeepAlive. #4882

Closed
wants to merge 1 commit into from

6 participants

@fastest963

See libuv pull request: joyent/libuv#729

@fastest963

I tried to make a test for this to include it with the commit, but unfortunately it's a lot harder than I thought to trick Linux into not sending a FIN/RST, so I just tested it by unplugging an ethernet cable of another computer and watching netstat -to or TCPView on Windows.

There is a check in libuv to at least set the params and make sure setsockopt doesn't fail.

@fastest963 fastest963 Added interval and count options to setKeepAlive.
The OS defaults for these are too extreme if you want to run a
chat server and know if someone disconnects. Changes go along
with libuv changes.
af16bc6
@Nodejs-Jenkins

Can one of the admins verify this patch?

@isaacs
Owner

The change looks fine (in master, not v0.10) but it needs a test.

@fastest963

@isaacs I mentioned above that there is a test in libuv for the setsockopt, but making a test for the actual keep-alive working was something I couldn't do. The best I could do is to get the kernel to send a RST to the other end, but as soon as Node got the RST it closed the connection. I need to somehow simulate a case where the receiving end doesn't respond to keep-alive's but didn't send a FIN/RST. Any ideas of how I would do that cross-platform?

@tjfontaine tjfontaine modified the milestone: v0.13, v0.12
@tjfontaine

I'm going to move this out to the 0.13 milestone as it has yet to have been addressed in libuv either.

But here are my $0.02 on this API, we should be exposing something along the lines of something more direct for setsockopt. This and the libuv portion add some of those concepts but without a flexible API. Also I'd probably advocate further additional arguments to be in objects not positional.

@trevnorris trevnorris added timer net and removed timer labels
@jasnell
Owner

Given that (a) this is an API change that had been pushed out to v0.13 and (b) the PR needs updating before it can hope to land, I'm going to recommend closing this. If someone wishes to pursue this further, updating the PR and targeting it against either http://github.com/nodejs/io.js or http://github.com/nodejs/node would be the most appropriate. Closing for now but can reopen if there are objections. /cc @joyent/node-tsc

@jasnell jasnell closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 5, 2013
  1. @fastest963

    Added interval and count options to setKeepAlive.

    fastest963 authored
    The OS defaults for these are too extreme if you want to run a
    chat server and know if someone disconnects. Changes go along
    with libuv changes.
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 9 deletions.
  1. +9 −6 doc/api/net.markdown
  2. +2 −2 lib/net.js
  3. +3 −1 src/tcp_wrap.cc
View
15 doc/api/net.markdown
@@ -388,16 +388,19 @@ algorithm, they buffer data before sending it off. Setting `true` for
`noDelay` will immediately fire off data each time `socket.write()` is called.
`noDelay` defaults to `true`.
-### socket.setKeepAlive([enable], [initialDelay])
+### socket.setKeepAlive([enable], [initialDelay], [probeInterval], [failureCount])
-Enable/disable keep-alive functionality, and optionally set the initial
-delay before the first keepalive probe is sent on an idle socket.
+Enable/disable keep-alive functionality, and optionally set keep-alive options.
+Options default to `0`, which leaves the value unchanged from the default
+(or previous) setting.
`enable` defaults to `false`.
Set `initialDelay` (in milliseconds) to set the delay between the last
-data packet received and the first keepalive probe. Setting 0 for
-initialDelay will leave the value unchanged from the default
-(or previous) setting. Defaults to `0`.
+data packet received and the first keepalive probe.
+Set `probeInterval` (in milliseconds) to set the interval between the
+keep-alive probes sent after the initial probe.
+Set `failureCount` to set the maximum number of probes that can fail before
+the OS closes the connection. Ignored on Windows.
### socket.address()
View
4 lib/net.js
@@ -294,9 +294,9 @@ Socket.prototype.setNoDelay = function(enable) {
};
-Socket.prototype.setKeepAlive = function(setting, msecs) {
+Socket.prototype.setKeepAlive = function(setting, msecs, interval, count) {
if (this._handle && this._handle.setKeepAlive)
- this._handle.setKeepAlive(setting, ~~(msecs / 1000));
+ this._handle.setKeepAlive(setting, ~~(msecs / 1000), ~~(interval / 1000), ~~count);
};
View
4 src/tcp_wrap.cc
@@ -230,8 +230,10 @@ Handle<Value> TCPWrap::SetKeepAlive(const Arguments& args) {
int enable = args[0]->Int32Value();
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)
SetErrno(uv_last_error(uv_default_loop()));
Something went wrong with that request. Please try again.