| 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) {
|
|
|