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

Unified Diff: net/socket/tcp_socket_libevent.cc

Issue 1215543003: Add UMA for the kernel's TCP RTT estimate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add WARN_UNUSED_RESULT. Created 5 years, 5 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 | « net/socket/tcp_socket_libevent.h ('k') | net/socket/tcp_socket_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/tcp_socket_libevent.cc
diff --git a/net/socket/tcp_socket_libevent.cc b/net/socket/tcp_socket_libevent.cc
index 6a6417b1ba12151a291b896312b93b9d27aeaa16..0eef1f5fbefa4a828be2bf8df6934bb076047732 100644
--- a/net/socket/tcp_socket_libevent.cc
+++ b/net/socket/tcp_socket_libevent.cc
@@ -114,6 +114,14 @@ void RegisterTCPFastOpenIntentAndSupport(bool user_enabled,
}
#endif
+#if defined(TCP_INFO)
+bool GetTcpInfo(SocketDescriptor fd, tcp_info* info) {
+ socklen_t info_len = sizeof(tcp_info);
+ return getsockopt(fd, IPPROTO_TCP, TCP_INFO, info, &info_len) == 0 &&
+ info_len == sizeof(tcp_info);
+}
+#endif // defined(TCP_INFO)
+
} // namespace
//-----------------------------------------------------------------------------
@@ -720,13 +728,10 @@ void TCPSocketLibevent::UpdateTCPFastOpenStatusAfterRead() {
#if defined(TCP_INFO)
// Probe to see the if the socket used TCP FastOpen.
tcp_info info;
- socklen_t info_len = sizeof(tcp_info);
- getsockopt_success = getsockopt(socket_->socket_fd(), IPPROTO_TCP, TCP_INFO,
- &info, &info_len) == 0 &&
- info_len == sizeof(tcp_info);
- server_acked_data = getsockopt_success &&
- (info.tcpi_options & TCPI_OPT_SYN_DATA);
-#endif
+ getsockopt_success = GetTcpInfo(socket_->socket_fd(), &info);
+ server_acked_data =
+ getsockopt_success && (info.tcpi_options & TCPI_OPT_SYN_DATA);
+#endif // defined(TCP_INFO)
if (getsockopt_success) {
if (tcp_fastopen_status_ == TCP_FASTOPEN_FAST_CONNECT_RETURN) {
@@ -746,4 +751,24 @@ void TCPSocketLibevent::UpdateTCPFastOpenStatusAfterRead() {
}
}
+bool TCPSocketLibevent::GetEstimatedRoundTripTime(
+ base::TimeDelta* out_rtt) const {
+ DCHECK(out_rtt);
+ if (!socket_)
+ return false;
+
+#if defined(TCP_INFO)
+ tcp_info info;
+ if (GetTcpInfo(socket_->socket_fd(), &info)) {
+ // tcpi_rtt is zero when the kernel doesn't have an RTT estimate,
+ // and possibly in other cases such as connections to localhost.
+ if (info.tcpi_rtt > 0) {
+ *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt);
+ return true;
+ }
+ }
+#endif // defined(TCP_INFO)
+ return false;
+}
+
} // namespace net
« no previous file with comments | « net/socket/tcp_socket_libevent.h ('k') | net/socket/tcp_socket_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698