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

Unified Diff: net/socket/tcp_client_socket_libevent.cc

Issue 6162005: Set TCP keep alive on Linux and Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Eliminate redundancy. 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_libevent.cc
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index bf6d3af648d6d8645376675535a5b2f16c4cfd5b..52956aa6f15866f1758d34a7dbcfb1676a34dcfb 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_);
wtc 2011/01/18 20:22:48 Please add a comment to explain why we need to set
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