Commit 67803e1f authored by willchan@chromium.org's avatar willchan@chromium.org

Reland 72421 - Enable TCP Keep-Alive packets for Windows.

Dropped the DCHECk since it seems some Windows version don't initialize the unused variable.

BUG=27400
TEST=none

Review URL: http://codereview.chromium.org/6242011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72429 0039d316-1c4b-4281-b951-d872f2087c98
parent b232f5b8
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "net/socket/tcp_client_socket_win.h" #include "net/socket/tcp_client_socket_win.h"
#include <mstcpip.h>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory_debug.h" #include "base/memory_debug.h"
...@@ -731,10 +733,26 @@ int TCPClientSocketWin::SetupSocket() { ...@@ -731,10 +733,26 @@ int TCPClientSocketWin::SetupSocket() {
// http://technet.microsoft.com/en-us/library/bb726981.aspx // http://technet.microsoft.com/en-us/library/bb726981.aspx
const BOOL kDisableNagle = TRUE; const BOOL kDisableNagle = TRUE;
int rv = setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, int rv = setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<const char*>(&kDisableNagle), sizeof(kDisableNagle)); reinterpret_cast<const char*>(&kDisableNagle),
sizeof(kDisableNagle));
DCHECK(!rv) << "Could not disable nagle"; DCHECK(!rv) << "Could not disable nagle";
// Disregard any failure in disabling nagle. // Enable TCP Keep-Alive to prevent NAT routers from timing out TCP
// connections. See http://crbug.com/27400 for details.
struct tcp_keepalive keepalive_vals = {
1, // TCP keep-alive on.
45000, // Wait 45s until sending first TCP keep-alive packet.
45000, // Wait 45s between sending TCP keep-alive packets.
};
DWORD bytes_returned = 0xABAB;
rv = WSAIoctl(socket_, SIO_KEEPALIVE_VALS, &keepalive_vals,
sizeof(keepalive_vals), NULL, 0,
&bytes_returned, NULL, NULL);
DCHECK(!rv) << "Could not enable TCP Keep-Alive for socket: " << socket_
<< " [error: " << WSAGetLastError() << "].";
// Disregard any failure in disabling nagle or enabling TCP Keep-Alive.
return 0; return 0;
} }
......
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