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

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: Created 5 years, 2 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/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 ca1f9e2439dd68c9f623a8b416dc5c9ae2372873..8d777d2bd32b86e7910ef2a6d4dc88b1f3681512 100644
--- a/net/udp/udp_client_socket.cc
+++ b/net/udp/udp_client_socket.cc
@@ -13,15 +13,41 @@ 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() {
+ int rv;
+ for (int attempt = 0; attempt < 5; attempt++) {
+ NetworkChangeNotifier::NetworkHandle network;
+ rv = NetworkChangeNotifier::GetDefaultNetwork(&network);
+ if (rv != OK)
+ return rv;
+ if (network == NetworkChangeNotifier::kInvalidNetworkHandle)
+ return ERR_INTERNET_DISCONNECTED;
+ rv = BindToNetwork(network);
+ // |network| may have disconnected between the time we query
+ // GetDefaultNetwork() and when we call 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