summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmenke <mmenke@chromium.org>2015-04-08 17:50:21 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-09 00:50:44 +0000
commit7e54f921781f44db1b4cf6002a0d180d37846c58 (patch)
tree1e6fb8861057fe176d4671b771ce9fb9f9bd420e
parent4ce665a95aeacb2bf1c83e110784226cc2536cc2 (diff)
downloadchromium_src-7e54f921781f44db1b4cf6002a0d180d37846c58.zip
chromium_src-7e54f921781f44db1b4cf6002a0d180d37846c58.tar.gz
chromium_src-7e54f921781f44db1b4cf6002a0d180d37846c58.tar.bz2
Add code to set TCP keep alive delay on OSX.
Previously, TCP keep alives were enabled on all desktop platforms, but the delay was not being set on OSX, resulting in not sending keep alives every 45 seconds, like on other platforms. This CL adds the code to do that. It does the same on iOS, though keep alives aren't enabled on mobile platforms, anyways. BUG=468764 Review URL: https://codereview.chromium.org/1065563006 Cr-Commit-Position: refs/heads/master@{#324319}
-rw-r--r--net/socket/tcp_socket_libevent.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/net/socket/tcp_socket_libevent.cc b/net/socket/tcp_socket_libevent.cc
index c5d30e1..56c19b2 100644
--- a/net/socket/tcp_socket_libevent.cc
+++ b/net/socket/tcp_socket_libevent.cc
@@ -56,6 +56,7 @@ bool SetTCPNoDelay(int fd, bool no_delay) {
// SetTCPKeepAlive sets SO_KEEPALIVE.
bool SetTCPKeepAlive(int fd, bool enable, int delay) {
+ // Enabling TCP keepalives is the same on all platforms.
int on = enable ? 1 : 0;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on))) {
PLOG(ERROR) << "Failed to set SO_KEEPALIVE on fd: " << fd;
@@ -67,6 +68,8 @@ bool SetTCPKeepAlive(int fd, bool enable, int delay) {
return true;
#if defined(OS_LINUX) || defined(OS_ANDROID)
+ // Setting the keepalive interval varies by platform.
+
// Set seconds until first TCP keep alive.
if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &delay, sizeof(delay))) {
PLOG(ERROR) << "Failed to set TCP_KEEPIDLE on fd: " << fd;
@@ -77,6 +80,11 @@ bool SetTCPKeepAlive(int fd, bool enable, int delay) {
PLOG(ERROR) << "Failed to set TCP_KEEPINTVL on fd: " << fd;
return false;
}
+#elif defined(OS_MACOSX) || defined(OS_IOS)
+ if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay))) {
+ PLOG(ERROR) << "Failed to set TCP_KEEPALIVE on fd: " << fd;
+ return false;
+ }
#endif
return true;
}