Commit 7e54f921 authored by mmenke's avatar mmenke Committed by Commit bot

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}
parent 4ce665a9
...@@ -56,6 +56,7 @@ bool SetTCPNoDelay(int fd, bool no_delay) { ...@@ -56,6 +56,7 @@ bool SetTCPNoDelay(int fd, bool no_delay) {
// SetTCPKeepAlive sets SO_KEEPALIVE. // SetTCPKeepAlive sets SO_KEEPALIVE.
bool SetTCPKeepAlive(int fd, bool enable, int delay) { bool SetTCPKeepAlive(int fd, bool enable, int delay) {
// Enabling TCP keepalives is the same on all platforms.
int on = enable ? 1 : 0; int on = enable ? 1 : 0;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on))) { if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on))) {
PLOG(ERROR) << "Failed to set SO_KEEPALIVE on fd: " << fd; PLOG(ERROR) << "Failed to set SO_KEEPALIVE on fd: " << fd;
...@@ -67,6 +68,8 @@ bool SetTCPKeepAlive(int fd, bool enable, int delay) { ...@@ -67,6 +68,8 @@ bool SetTCPKeepAlive(int fd, bool enable, int delay) {
return true; return true;
#if defined(OS_LINUX) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_ANDROID)
// Setting the keepalive interval varies by platform.
// Set seconds until first TCP keep alive. // Set seconds until first TCP keep alive.
if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &delay, sizeof(delay))) { if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &delay, sizeof(delay))) {
PLOG(ERROR) << "Failed to set TCP_KEEPIDLE on fd: " << fd; PLOG(ERROR) << "Failed to set TCP_KEEPIDLE on fd: " << fd;
...@@ -77,6 +80,11 @@ bool SetTCPKeepAlive(int fd, bool enable, int delay) { ...@@ -77,6 +80,11 @@ bool SetTCPKeepAlive(int fd, bool enable, int delay) {
PLOG(ERROR) << "Failed to set TCP_KEEPINTVL on fd: " << fd; PLOG(ERROR) << "Failed to set TCP_KEEPINTVL on fd: " << fd;
return false; 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 #endif
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment