OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/udp/udp_socket_posix.h" | 5 #include "net/udp/udp_socket_posix.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <net/if.h> | 9 #include <net/if.h> |
10 #include <netdb.h> | 10 #include <netdb.h> |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 if (rv < 0) | 319 if (rv < 0) |
320 return rv; | 320 return rv; |
321 | 321 |
322 is_connected_ = true; | 322 is_connected_ = true; |
323 local_address_.reset(); | 323 local_address_.reset(); |
324 return rv; | 324 return rv; |
325 } | 325 } |
326 | 326 |
327 int UDPSocketPosix::BindToNetwork( | 327 int UDPSocketPosix::BindToNetwork( |
328 NetworkChangeNotifier::NetworkHandle network) { | 328 NetworkChangeNotifier::NetworkHandle network) { |
329 #if defined(OS_ANDROID) | |
330 DCHECK_NE(socket_, kInvalidSocket); | 329 DCHECK_NE(socket_, kInvalidSocket); |
331 DCHECK(CalledOnValidThread()); | 330 DCHECK(CalledOnValidThread()); |
332 DCHECK(!is_connected()); | 331 DCHECK(!is_connected()); |
332 if (network == NetworkChangeNotifier::kInvalidNetworkHandle) | |
333 return ERR_INVALID_ARGUMENT; | |
334 #if defined(OS_ANDROID) | |
333 // Android prior to Lollipop didn't have support for binding sockets to | 335 // Android prior to Lollipop didn't have support for binding sockets to |
334 // networks. | 336 // networks. |
335 if (base::android::BuildInfo::GetInstance()->sdk_int() < | 337 if (base::android::BuildInfo::GetInstance()->sdk_int() < |
336 base::android::SDK_VERSION_LOLLIPOP) { | 338 base::android::SDK_VERSION_LOLLIPOP) { |
337 return ERR_NOT_IMPLEMENTED; | 339 return ERR_NOT_IMPLEMENTED; |
Jana
2015/12/04 20:30:16
Not for this CL, but this seems like another platf
pauljensen
2015/12/07 13:05:55
Why? This support check is directly related to th
Jana
2015/12/07 17:30:52
Oh yes, apologies -- this doesn't belong in NCN. W
| |
338 } | 340 } |
339 // NOTE(pauljensen): This does rely on Android implementation details, but | 341 // NOTE(pauljensen): This does rely on Android implementation details, but |
340 // these details are unlikely to change. | 342 // these details are unlikely to change. |
341 typedef int (*SetNetworkForSocket)(unsigned netId, int socketFd); | 343 typedef int (*SetNetworkForSocket)(unsigned netId, int socketFd); |
342 static SetNetworkForSocket setNetworkForSocket; | 344 static SetNetworkForSocket setNetworkForSocket; |
343 // This is racy, but all racers should come out with the same answer so it | 345 // This is racy, but all racers should come out with the same answer so it |
344 // shouldn't matter. | 346 // shouldn't matter. |
345 if (setNetworkForSocket == nullptr) { | 347 if (setNetworkForSocket == nullptr) { |
346 // Android's netd client library should always be loaded in our address | 348 // Android's netd client library should always be loaded in our address |
347 // space as it shims libc functions like connect(). | 349 // space as it shims libc functions like connect(). |
348 base::FilePath file(base::FilePath::FromUTF16Unsafe( | 350 base::FilePath file(base::FilePath::FromUTF16Unsafe( |
349 base::GetNativeLibraryName(base::ASCIIToUTF16("netd_client")))); | 351 base::GetNativeLibraryName(base::ASCIIToUTF16("netd_client")))); |
350 base::NativeLibrary lib = base::LoadNativeLibrary(file, nullptr); | 352 base::NativeLibrary lib = base::LoadNativeLibrary(file, nullptr); |
351 setNetworkForSocket = reinterpret_cast<SetNetworkForSocket>( | 353 setNetworkForSocket = reinterpret_cast<SetNetworkForSocket>( |
352 base::GetFunctionPointerFromNativeLibrary(lib, "setNetworkForSocket")); | 354 base::GetFunctionPointerFromNativeLibrary(lib, "setNetworkForSocket")); |
353 } | 355 } |
354 if (setNetworkForSocket == nullptr) | 356 if (setNetworkForSocket == nullptr) |
355 return ERR_NOT_IMPLEMENTED; | 357 return ERR_NOT_IMPLEMENTED; |
356 return MapSystemError(setNetworkForSocket(network, socket_)); | 358 int rv = setNetworkForSocket(network, socket_); |
359 // If |network| has since disconnected, |rv| will be ENONET. Surface this as | |
360 // ERR_NETWORK_CHANGED, rather than MapSystemError(ENONET) which gives back | |
361 // the less descriptive ERR_FAILED. | |
362 if (rv == ENONET) | |
363 return ERR_NETWORK_CHANGED; | |
Jana
2015/12/04 20:30:16
This is probably fine, but shouldn't this be ERR_I
pauljensen
2015/12/07 13:05:55
ERR_INTERNET_DISCONNECTED means there are no netwo
| |
364 return MapSystemError(rv); | |
357 #else | 365 #else |
358 NOTIMPLEMENTED(); | 366 NOTIMPLEMENTED(); |
359 return ERR_NOT_IMPLEMENTED; | 367 return ERR_NOT_IMPLEMENTED; |
360 #endif | 368 #endif |
361 } | 369 } |
362 | 370 |
363 int UDPSocketPosix::SetReceiveBufferSize(int32_t size) { | 371 int UDPSocketPosix::SetReceiveBufferSize(int32_t size) { |
364 DCHECK_NE(socket_, kInvalidSocket); | 372 DCHECK_NE(socket_, kInvalidSocket); |
365 DCHECK(CalledOnValidThread()); | 373 DCHECK(CalledOnValidThread()); |
366 int rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF, | 374 int rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF, |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 return MapSystemError(errno); | 794 return MapSystemError(errno); |
787 | 795 |
788 return OK; | 796 return OK; |
789 } | 797 } |
790 | 798 |
791 void UDPSocketPosix::DetachFromThread() { | 799 void UDPSocketPosix::DetachFromThread() { |
792 base::NonThreadSafe::DetachFromThread(); | 800 base::NonThreadSafe::DetachFromThread(); |
793 } | 801 } |
794 | 802 |
795 } // namespace net | 803 } // namespace net |
OLD | NEW |