Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Unified Diff: net/socket/tcp_client_socket_win.cc

Issue 6242011: Reland 72421 - Enable TCP Keep-Alive packets for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/tcp_client_socket_win.cc
diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc
index e8b2f5303846a29297c0574f6de7822b02a84ff8..b33c6de3d493796f81053a773e93e0587e32fced 100644
--- a/net/socket/tcp_client_socket_win.cc
+++ b/net/socket/tcp_client_socket_win.cc
@@ -4,6 +4,8 @@
#include "net/socket/tcp_client_socket_win.h"
+#include <mstcpip.h>
+
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory_debug.h"
@@ -731,10 +733,26 @@ int TCPClientSocketWin::SetupSocket() {
// http://technet.microsoft.com/en-us/library/bb726981.aspx
const BOOL kDisableNagle = TRUE;
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";
- // 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;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698