Index: net/udp/udp_socket_posix.cc |
diff --git a/net/udp/udp_socket_posix.cc b/net/udp/udp_socket_posix.cc |
index f747798afe5772e8856947b719b7aa3480a8a4e6..13c96f213caf4078798e4a01df6b8cd8c8559cb1 100644 |
--- a/net/udp/udp_socket_posix.cc |
+++ b/net/udp/udp_socket_posix.cc |
@@ -326,10 +326,12 @@ int UDPSocketPosix::Bind(const IPEndPoint& address) { |
int UDPSocketPosix::BindToNetwork( |
NetworkChangeNotifier::NetworkHandle network) { |
-#if defined(OS_ANDROID) |
DCHECK_NE(socket_, kInvalidSocket); |
DCHECK(CalledOnValidThread()); |
DCHECK(!is_connected()); |
+ if (network == NetworkChangeNotifier::kInvalidNetworkHandle) |
+ return ERR_INVALID_ARGUMENT; |
+#if defined(OS_ANDROID) |
// Android prior to Lollipop didn't have support for binding sockets to |
// networks. |
if (base::android::BuildInfo::GetInstance()->sdk_int() < |
@@ -353,7 +355,13 @@ int UDPSocketPosix::BindToNetwork( |
} |
if (setNetworkForSocket == nullptr) |
return ERR_NOT_IMPLEMENTED; |
- return MapSystemError(setNetworkForSocket(network, socket_)); |
+ int rv = setNetworkForSocket(network, socket_); |
+ // If |network| has since disconnected, surface this as ERR_NETWORK_CHANGED, |
+ // rather than MapSystemError(ENONET) giving back the less descriptive |
+ // ERR_FAILED. |
+ if (rv == ENONET) |
+ return ERR_NETWORK_CHANGED; |
+ return MapSystemError(rv); |
#else |
NOTIMPLEMENTED(); |
return ERR_NOT_IMPLEMENTED; |