diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-14 20:41:27 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-14 20:41:27 +0000 |
commit | cd2fbf59f5052609e543f55d1edd29d41f8b7e85 (patch) | |
tree | 27856fdbc900d46dc192aa922382cf371111f48a | |
parent | fd2e53e0043ddab5d0ef4e9ce6dd8c9808e3ea57 (diff) | |
download | chromium_src-cd2fbf59f5052609e543f55d1edd29d41f8b7e85.zip chromium_src-cd2fbf59f5052609e543f55d1edd29d41f8b7e85.tar.gz chromium_src-cd2fbf59f5052609e543f55d1edd29d41f8b7e85.tar.bz2 |
Set TCP keep alive on Linux and Mac.
On Linux, also set the timeouts.
BUG=27400
TEST=Start wireshark and capture packets. Start chrome. Open www.facebook.com. Let it sit idle for awhile. Wait for TCP keep alive packets to be sent out after 45 seconds on Linux.
Review URL: http://codereview.chromium.org/6162005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71482 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/socket/tcp_client_socket_libevent.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc index bf6d3af..52956aa 100644 --- a/net/socket/tcp_client_socket_libevent.cc +++ b/net/socket/tcp_client_socket_libevent.cc @@ -45,6 +45,29 @@ int DisableNagle(int fd) { return setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); } +// SetTCPKeepAlive sets SO_KEEPALIVE. +void SetTCPKeepAlive(int fd) { + int optval = 1; + socklen_t optlen = sizeof(optval); + if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen)) { + PLOG(ERROR) << "Failed to set SO_KEEPALIVE on fd: " << fd; + return; + } +#if defined(OS_LINUX) + // Set seconds until first TCP keep alive. + optval = 45; + if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &optval, optlen)) { + PLOG(ERROR) << "Failed to set TCP_KEEPIDLE on fd: " << fd; + return; + } + // Set seconds between TCP keep alives. + if (setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &optval, optlen)) { + PLOG(ERROR) << "Failed to set TCP_KEEPINTVL on fd: " << fd; + return; + } +#endif +} + // Convert values from <errno.h> to values from "net/base/net_errors.h" int MapPosixError(int os_error) { // There are numerous posix error codes, but these are the ones we thus far @@ -493,6 +516,7 @@ int TCPClientSocketLibevent::SetupSocket() { // This mirrors the behaviour on Windows. See the comment in // tcp_client_socket_win.cc after searching for "NODELAY". DisableNagle(socket_); // If DisableNagle fails, we don't care. + SetTCPKeepAlive(socket_); return 0; } |