diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-05 23:22:16 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-05 23:22:16 +0000 |
commit | 837ab170a0bc78ac733f3a6f747b2b2c5e2f15a0 (patch) | |
tree | e9516ef188a0c3f165ba60de49a1df07281f9893 /net | |
parent | fa8d1b6309d43f18e8579a2175097a4d294a3ecd (diff) | |
download | chromium_src-837ab170a0bc78ac733f3a6f747b2b2c5e2f15a0.zip chromium_src-837ab170a0bc78ac733f3a6f747b2b2c5e2f15a0.tar.gz chromium_src-837ab170a0bc78ac733f3a6f747b2b2c5e2f15a0.tar.bz2 |
Disable TCP Keep Alive on mobile to reduce power usage.
TCP Keep Alives will periodically send TCP packets to keep the
connection alive. This may wake up the radio, which is expensive in
terms of power utilization. Disable it on mobile.
BUG=258361
Review URL: https://codereview.chromium.org/106003004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243047 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/socket/tcp_socket_libevent.cc | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/net/socket/tcp_socket_libevent.cc b/net/socket/tcp_socket_libevent.cc index f4e4fe8..94d2897 100644 --- a/net/socket/tcp_socket_libevent.cc +++ b/net/socket/tcp_socket_libevent.cc @@ -35,8 +35,6 @@ namespace net { namespace { -const int kTCPKeepAliveSeconds = 45; - // SetTCPNoDelay turns on/off buffering in the kernel. By default, TCP sockets // will wait up to 200ms for more data to complete a packet before transmitting. // After calling this function, the kernel will not wait. See TCP_NODELAY in @@ -54,6 +52,11 @@ bool SetTCPKeepAlive(int fd, bool enable, int delay) { PLOG(ERROR) << "Failed to set SO_KEEPALIVE on fd: " << fd; return false; } + + // If we disabled TCP keep alive, our work is done here. + if (!enable) + return true; + #if defined(OS_LINUX) || defined(OS_ANDROID) // Set seconds until first TCP keep alive. if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &delay, sizeof(delay))) { @@ -455,7 +458,23 @@ void TCPSocketLibevent::SetDefaultOptionsForClient() { // This mirrors the behaviour on Windows. See the comment in // tcp_socket_win.cc after searching for "NODELAY". SetTCPNoDelay(socket_, true); // If SetTCPNoDelay fails, we don't care. + + // TCP keep alive wakes up the radio, which is expensive on mobile. Do not + // enable it there. It's useful to prevent TCP middleboxes from timing out + // connection mappings. Packets for timed out connection mappings at + // middleboxes will either lead to: + // a) Middleboxes sending TCP RSTs. It's up to higher layers to check for this + // and retry. The HTTP network transaction code does this. + // b) Middleboxes just drop the unrecognized TCP packet. This leads to the TCP + // stack retransmitting packets per TCP stack retransmission timeouts, which + // are very high (on the order of seconds). Given the number of + // retransmissions required before killing the connection, this can lead to + // tens of seconds or even minutes of delay, depending on OS. +#if !defined(OS_ANDROID) && !defined(OS_IOS) + const int kTCPKeepAliveSeconds = 45; + SetTCPKeepAlive(socket_, true, kTCPKeepAliveSeconds); +#endif } int TCPSocketLibevent::SetAddressReuse(bool allow) { |