summaryrefslogtreecommitdiffstats
path: root/net/base/net_util.cc
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-08 22:15:54 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-08 22:15:54 +0000
commit32eaa332c7ef3f5480b0e5cfc4f42418a13c9189 (patch)
tree2d3155f68162a9523b1b12cbb54c8a35863664a7 /net/base/net_util.cc
parent26788a65a7f9094a0acd44ea69c3cdbea5b1f498 (diff)
downloadchromium_src-32eaa332c7ef3f5480b0e5cfc4f42418a13c9189.zip
chromium_src-32eaa332c7ef3f5480b0e5cfc4f42418a13c9189.tar.gz
chromium_src-32eaa332c7ef3f5480b0e5cfc4f42418a13c9189.tar.bz2
Add IPv6 probing support, and disable IPv6 resolution when it is useless
I've added minimal probing to check if IPv6 is at all possible, and when it is not, then we disable IPv6 resolution. I've also added histograms and A/B test support to evaluate the impact of this change. (I landed originally, but had tree problems, and this is a new CL to tryto reland). Note that I've switched back to MACRO style enums as well, per http://dev.chromium.org/developers/coding-style (search for "enum"). This version now does the conditional testing at a higher level (in io_thread.h), so that it should interfere less with other testing. r=wtc,eroman Review URL: http://codereview.chromium.org/585005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38402 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r--net/base/net_util.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 43fa906..a2eb04d 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1538,4 +1538,54 @@ void SetExplicitlyAllowedPorts(const std::wstring& allowed_ports) {
explicitly_allowed_ports = ports;
}
+enum IPv6SupportStatus {
+ IPV6_CANNOT_CREATE_SOCKETS,
+ IPV6_CAN_CREATE_SOCKETS,
+ IPV6_SUPPORT_MAX // Bounding values for enumeration.
+};
+
+static void IPv6SupportResults(IPv6SupportStatus result) {
+ static bool run_once = false;
+ if (run_once)
+ return;
+ run_once = true;
+ UMA_HISTOGRAM_ENUMERATION("Net.IPv6Status", result, IPV6_SUPPORT_MAX);
+}
+
+// TODO(jar): The following is a simple estimate of IPv6 support. We may need
+// to do a test resolution, and a test connection, to REALLY verify support.
+// static
+bool IPv6Supported() {
+#if defined(OS_POSIX)
+ int test_socket;
+
+ test_socket = socket(AF_INET6, SOCK_STREAM, 0);
+ if (test_socket == -1) {
+ IPv6SupportResults(IPV6_CANNOT_CREATE_SOCKETS);
+ return false;
+ }
+
+ close(test_socket);
+ IPv6SupportResults(IPV6_CAN_CREATE_SOCKETS);
+ return true;
+#elif defined(OS_WIN)
+ EnsureWinsockInit();
+ SOCKET test_socket;
+
+ test_socket = socket(AF_INET6, SOCK_STREAM, 0);
+ if (test_socket == INVALID_SOCKET) {
+ IPv6SupportResults(IPV6_CANNOT_CREATE_SOCKETS);
+ return false;
+ }
+
+ closesocket(test_socket);
+ IPv6SupportResults(IPV6_CAN_CREATE_SOCKETS);
+ return true;
+#else
+ NOTIMPLEMENTED();
+ return true;
+#endif // defined(various platforms)
+}
+
+
} // namespace net