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

Unified Diff: net/udp/udp_client_socket.cc

Issue 1416213003: Add DatagramClientSocket::BindToDefaultNetwork(),GetBoundNetwork() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: loop only twice Created 5 years 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/udp/udp_client_socket.h ('k') | net/udp/udp_socket_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/udp/udp_client_socket.cc
diff --git a/net/udp/udp_client_socket.cc b/net/udp/udp_client_socket.cc
index a991f10bd0c527a4cf211867a975f1778e7a1507..b64643ce01148b2720cee72cd9a2d8919b30ce68 100644
--- a/net/udp/udp_client_socket.cc
+++ b/net/udp/udp_client_socket.cc
@@ -13,15 +13,48 @@ UDPClientSocket::UDPClientSocket(DatagramSocket::BindType bind_type,
const RandIntCallback& rand_int_cb,
net::NetLog* net_log,
const net::NetLog::Source& source)
- : socket_(bind_type, rand_int_cb, net_log, source) {
-}
+ : socket_(bind_type, rand_int_cb, net_log, source),
+ network_(NetworkChangeNotifier::kInvalidNetworkHandle) {}
UDPClientSocket::~UDPClientSocket() {
}
int UDPClientSocket::BindToNetwork(
NetworkChangeNotifier::NetworkHandle network) {
- return socket_.BindToNetwork(network);
+ int rv = socket_.BindToNetwork(network);
+ if (rv == OK)
+ network_ = network;
+ return rv;
+}
+
+int UDPClientSocket::BindToDefaultNetwork() {
+ if (!NetworkChangeNotifier::AreNetworkHandlesSupported())
+ return ERR_NOT_IMPLEMENTED;
+ int rv;
+ // Calling connect() will bind a socket to the default network, however there
+ // is no way to determine what network the socket got bound to. The
+ // alternative is to query what the default network is and bind the socket to
+ // that network explicitly, however this is racy because the default network
+ // can change in between when we query it and when we bind to it. This is
+ // rare but should be accounted for. Since changes of the default network
+ // should not come in quick succession, we can simply try again.
+ for (int attempt = 0; attempt < 2; attempt++) {
+ NetworkChangeNotifier::NetworkHandle network =
+ NetworkChangeNotifier::GetDefaultNetwork();
+ if (network == NetworkChangeNotifier::kInvalidNetworkHandle)
+ return ERR_INTERNET_DISCONNECTED;
+ rv = BindToNetwork(network);
+ // |network| may have disconnected between the call to GetDefaultNetwork()
+ // and the call to BindToNetwork(). Loop if this is the case (|rv| will be
+ // ERR_NETWORK_CHANGED).
+ if (rv != ERR_NETWORK_CHANGED)
+ return rv;
+ }
+ return rv;
+}
+
+NetworkChangeNotifier::NetworkHandle UDPClientSocket::GetBoundNetwork() {
+ return network_;
}
int UDPClientSocket::Connect(const IPEndPoint& address) {
« no previous file with comments | « net/udp/udp_client_socket.h ('k') | net/udp/udp_socket_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698