summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-02-08 17:06:01 +0100
committerantirez <antirez@gmail.com>2013-02-11 11:47:31 +0100
commit2d89c53d0d9c4a29ab299568b90137ff6926b6f7 (patch)
tree788b790ff8f553c4859a91c3b9df549ac9c3d2b9
parent0fe052efaa6b7490b29a0073826ca3d1cc6a4754 (diff)
downloadredis-2d89c53d0d9c4a29ab299568b90137ff6926b6f7.tar.gz
Tcp keep-alive: send three probes before detectin an error.
Otherwise we end with less reliable connections because it's too easy that a single packet gets lost.
-rw-r--r--src/anet.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/anet.c b/src/anet.c
index 82bca5534..963b6688e 100644
--- a/src/anet.c
+++ b/src/anet.c
@@ -100,15 +100,19 @@ int anetKeepAlive(char *err, int fd, int interval)
return ANET_ERR;
}
- /* Send next probes after interval. */
- val = interval;
+ /* Send next probes after the specified interval. Note that we set the
+ * delay as interval / 3, as we send three probes before detecting
+ * an error (see the next setsockopt call). */
+ val = interval/3;
+ if (val == 0) val = 1;
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof(val)) < 0) {
anetSetError(err, "setsockopt TCP_KEEPINTVL: %s\n", strerror(errno));
return ANET_ERR;
}
- /* Consider the socket in error state after just one missing ACK reply. */
- val = 1;
+ /* Consider the socket in error state after three we send three ACK
+ * probes without getting a reply. */
+ val = 3;
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &val, sizeof(val)) < 0) {
anetSetError(err, "setsockopt TCP_KEEPCNT: %s\n", strerror(errno));
return ANET_ERR;