Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/socket/tcp_socket.h" | 5 #include "net/socket/tcp_socket.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <netinet/tcp.h> | 8 #include <netinet/tcp.h> |
| 9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 return true; | 107 return true; |
| 108 } | 108 } |
| 109 | 109 |
| 110 void RegisterTCPFastOpenIntentAndSupport(bool user_enabled, | 110 void RegisterTCPFastOpenIntentAndSupport(bool user_enabled, |
| 111 bool system_supported) { | 111 bool system_supported) { |
| 112 g_tcp_fastopen_supported = system_supported; | 112 g_tcp_fastopen_supported = system_supported; |
| 113 g_tcp_fastopen_user_enabled = user_enabled; | 113 g_tcp_fastopen_user_enabled = user_enabled; |
| 114 } | 114 } |
| 115 #endif | 115 #endif |
| 116 | 116 |
| 117 #if defined(TCP_INFO) | |
| 118 bool GetTcpInfo(SocketDescriptor fd, tcp_info* info) { | |
| 119 socklen_t info_len = sizeof(tcp_info); | |
| 120 return getsockopt(fd, IPPROTO_TCP, TCP_INFO, info, &info_len) == 0 && | |
| 121 info_len == sizeof(tcp_info); | |
| 122 } | |
| 123 #endif // defined(TCP_INFO) | |
| 124 | |
| 117 } // namespace | 125 } // namespace |
| 118 | 126 |
| 119 //----------------------------------------------------------------------------- | 127 //----------------------------------------------------------------------------- |
| 120 | 128 |
| 121 bool IsTCPFastOpenSupported() { | 129 bool IsTCPFastOpenSupported() { |
| 122 return g_tcp_fastopen_supported; | 130 return g_tcp_fastopen_supported; |
| 123 } | 131 } |
| 124 | 132 |
| 125 bool IsTCPFastOpenUserEnabled() { | 133 bool IsTCPFastOpenUserEnabled() { |
| 126 return g_tcp_fastopen_user_enabled; | 134 return g_tcp_fastopen_user_enabled; |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 TCP_FASTOPEN_FAST_CONNECT_READ_FAILED : | 721 TCP_FASTOPEN_FAST_CONNECT_READ_FAILED : |
| 714 TCP_FASTOPEN_SLOW_CONNECT_READ_FAILED); | 722 TCP_FASTOPEN_SLOW_CONNECT_READ_FAILED); |
| 715 return; | 723 return; |
| 716 } | 724 } |
| 717 | 725 |
| 718 bool getsockopt_success = false; | 726 bool getsockopt_success = false; |
| 719 bool server_acked_data = false; | 727 bool server_acked_data = false; |
| 720 #if defined(TCP_INFO) | 728 #if defined(TCP_INFO) |
| 721 // Probe to see the if the socket used TCP FastOpen. | 729 // Probe to see the if the socket used TCP FastOpen. |
| 722 tcp_info info; | 730 tcp_info info; |
| 723 socklen_t info_len = sizeof(tcp_info); | 731 getsockopt_success = GetTcpInfo(socket_->socket_fd(), &info); |
| 724 getsockopt_success = getsockopt(socket_->socket_fd(), IPPROTO_TCP, TCP_INFO, | 732 server_acked_data = |
| 725 &info, &info_len) == 0 && | 733 getsockopt_success && (info.tcpi_options & TCPI_OPT_SYN_DATA); |
| 726 info_len == sizeof(tcp_info); | 734 #endif // defined(TCP_INFO) |
| 727 server_acked_data = getsockopt_success && | |
| 728 (info.tcpi_options & TCPI_OPT_SYN_DATA); | |
| 729 #endif | |
| 730 | 735 |
| 731 if (getsockopt_success) { | 736 if (getsockopt_success) { |
| 732 if (tcp_fastopen_status_ == TCP_FASTOPEN_FAST_CONNECT_RETURN) { | 737 if (tcp_fastopen_status_ == TCP_FASTOPEN_FAST_CONNECT_RETURN) { |
| 733 tcp_fastopen_status_ = (server_acked_data ? | 738 tcp_fastopen_status_ = (server_acked_data ? |
| 734 TCP_FASTOPEN_SYN_DATA_ACK : | 739 TCP_FASTOPEN_SYN_DATA_ACK : |
| 735 TCP_FASTOPEN_SYN_DATA_NACK); | 740 TCP_FASTOPEN_SYN_DATA_NACK); |
| 736 } else { | 741 } else { |
| 737 tcp_fastopen_status_ = (server_acked_data ? | 742 tcp_fastopen_status_ = (server_acked_data ? |
| 738 TCP_FASTOPEN_NO_SYN_DATA_ACK : | 743 TCP_FASTOPEN_NO_SYN_DATA_ACK : |
| 739 TCP_FASTOPEN_NO_SYN_DATA_NACK); | 744 TCP_FASTOPEN_NO_SYN_DATA_NACK); |
| 740 } | 745 } |
| 741 } else { | 746 } else { |
| 742 tcp_fastopen_status_ = | 747 tcp_fastopen_status_ = |
| 743 (tcp_fastopen_status_ == TCP_FASTOPEN_FAST_CONNECT_RETURN ? | 748 (tcp_fastopen_status_ == TCP_FASTOPEN_FAST_CONNECT_RETURN ? |
| 744 TCP_FASTOPEN_SYN_DATA_GETSOCKOPT_FAILED : | 749 TCP_FASTOPEN_SYN_DATA_GETSOCKOPT_FAILED : |
| 745 TCP_FASTOPEN_NO_SYN_DATA_GETSOCKOPT_FAILED); | 750 TCP_FASTOPEN_NO_SYN_DATA_GETSOCKOPT_FAILED); |
| 746 } | 751 } |
| 747 } | 752 } |
| 748 | 753 |
| 754 bool TCPSocketLibevent::GetEstimatedRoundTripTime(base::TimeDelta* out_rtt) { | |
| 755 DCHECK(out_rtt); | |
| 756 if (!socket_) | |
| 757 return false; | |
| 758 | |
| 759 #if defined(TCP_INFO) | |
| 760 tcp_info info; | |
| 761 if (GetTcpInfo(socket_->socket_fd(), &info)) { | |
| 762 // When the kernel doesn't have an RTT estimate, tcpi_rtt is zero. | |
|
mmenke
2015/07/07 21:27:29
May be worth mentioning that it may be 0 in other
Bryan McQuade
2015/07/08 00:35:37
Done.
| |
| 763 if (info.tcpi_rtt > 0) { | |
| 764 *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt); | |
| 765 return true; | |
| 766 } | |
| 767 } | |
| 768 #endif // defined(TCP_INFO) | |
| 769 return false; | |
| 770 } | |
| 771 | |
| 749 } // namespace net | 772 } // namespace net |
| OLD | NEW |