Chromium Code Reviews| 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 <dlfcn.h> | |
|
xunjieli
2016/06/29 13:35:09
Should this header be in the #if defined(OS_ANDROI
pauljensen
2016/06/29 13:45:49
Done.
| |
| 7 #include <errno.h> | 8 #include <errno.h> |
| 8 #include <fcntl.h> | 9 #include <fcntl.h> |
| 9 #include <net/if.h> | 10 #include <net/if.h> |
| 10 #include <netdb.h> | 11 #include <netdb.h> |
| 11 #include <netinet/in.h> | 12 #include <netinet/in.h> |
| 12 #include <sys/ioctl.h> | 13 #include <sys/ioctl.h> |
| 13 #include <sys/socket.h> | 14 #include <sys/socket.h> |
| 14 | 15 |
| 15 #include "base/callback.h" | 16 #include "base/callback.h" |
| 16 #include "base/debug/alias.h" | 17 #include "base/debug/alias.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 28 #include "net/base/network_activity_monitor.h" | 29 #include "net/base/network_activity_monitor.h" |
| 29 #include "net/base/sockaddr_storage.h" | 30 #include "net/base/sockaddr_storage.h" |
| 30 #include "net/log/net_log.h" | 31 #include "net/log/net_log.h" |
| 31 #include "net/socket/socket_descriptor.h" | 32 #include "net/socket/socket_descriptor.h" |
| 32 #include "net/udp/udp_net_log_parameters.h" | 33 #include "net/udp/udp_net_log_parameters.h" |
| 33 | 34 |
| 34 #if defined(OS_ANDROID) | 35 #if defined(OS_ANDROID) |
| 35 #include "base/android/build_info.h" | 36 #include "base/android/build_info.h" |
| 36 #include "base/native_library.h" | 37 #include "base/native_library.h" |
| 37 #include "base/strings/utf_string_conversions.h" | 38 #include "base/strings/utf_string_conversions.h" |
| 39 // This was added in Lollipop to dlfcn.h | |
| 40 #define RTLD_NOLOAD 4 | |
| 38 #endif | 41 #endif |
| 39 | 42 |
| 40 namespace net { | 43 namespace net { |
| 41 | 44 |
| 42 namespace { | 45 namespace { |
| 43 | 46 |
| 44 const int kBindRetries = 10; | 47 const int kBindRetries = 10; |
| 45 const int kPortStart = 1024; | 48 const int kPortStart = 1024; |
| 46 const int kPortEnd = 65535; | 49 const int kPortEnd = 65535; |
| 47 | 50 |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 return ERR_NOT_IMPLEMENTED; | 347 return ERR_NOT_IMPLEMENTED; |
| 345 } | 348 } |
| 346 // NOTE(pauljensen): This does rely on Android implementation details, but | 349 // NOTE(pauljensen): This does rely on Android implementation details, but |
| 347 // these details are unlikely to change. | 350 // these details are unlikely to change. |
| 348 typedef int (*SetNetworkForSocket)(unsigned netId, int socketFd); | 351 typedef int (*SetNetworkForSocket)(unsigned netId, int socketFd); |
| 349 static SetNetworkForSocket setNetworkForSocket; | 352 static SetNetworkForSocket setNetworkForSocket; |
| 350 // This is racy, but all racers should come out with the same answer so it | 353 // This is racy, but all racers should come out with the same answer so it |
| 351 // shouldn't matter. | 354 // shouldn't matter. |
| 352 if (!setNetworkForSocket) { | 355 if (!setNetworkForSocket) { |
| 353 // Android's netd client library should always be loaded in our address | 356 // Android's netd client library should always be loaded in our address |
| 354 // space as it shims libc functions like connect(). | 357 // space as it shims socket() which was used to create |socket_|. |
| 355 base::FilePath file(base::GetNativeLibraryName("netd_client")); | 358 base::FilePath file(base::GetNativeLibraryName("netd_client")); |
| 356 base::NativeLibrary lib = base::LoadNativeLibrary(file, nullptr); | 359 void* dl = dlopen(file.value().c_str(), RTLD_NOW | RTLD_NOLOAD); |
|
xunjieli
2016/06/29 13:35:09
Could add a brief comment on the flags (RTLD_NOW |
pauljensen
2016/06/29 13:45:50
Done.
| |
| 357 setNetworkForSocket = reinterpret_cast<SetNetworkForSocket>( | 360 setNetworkForSocket = |
| 358 base::GetFunctionPointerFromNativeLibrary(lib, "setNetworkForSocket")); | 361 reinterpret_cast<SetNetworkForSocket>(dlsym(dl, "setNetworkForSocket")); |
| 359 } | 362 } |
| 360 if (!setNetworkForSocket) | 363 if (!setNetworkForSocket) |
| 361 return ERR_NOT_IMPLEMENTED; | 364 return ERR_NOT_IMPLEMENTED; |
| 362 int rv = setNetworkForSocket(network, socket_); | 365 int rv = setNetworkForSocket(network, socket_); |
| 363 // If |network| has since disconnected, |rv| will be ENONET. Surface this as | 366 // If |network| has since disconnected, |rv| will be ENONET. Surface this as |
| 364 // ERR_NETWORK_CHANGED, rather than MapSystemError(ENONET) which gives back | 367 // ERR_NETWORK_CHANGED, rather than MapSystemError(ENONET) which gives back |
| 365 // the less descriptive ERR_FAILED. | 368 // the less descriptive ERR_FAILED. |
| 366 if (rv == ENONET) | 369 if (rv == ENONET) |
| 367 return ERR_NETWORK_CHANGED; | 370 return ERR_NETWORK_CHANGED; |
| 368 if (rv == 0) | 371 if (rv == 0) |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 return MapSystemError(errno); | 809 return MapSystemError(errno); |
| 807 | 810 |
| 808 return OK; | 811 return OK; |
| 809 } | 812 } |
| 810 | 813 |
| 811 void UDPSocketPosix::DetachFromThread() { | 814 void UDPSocketPosix::DetachFromThread() { |
| 812 base::NonThreadSafe::DetachFromThread(); | 815 base::NonThreadSafe::DetachFromThread(); |
| 813 } | 816 } |
| 814 | 817 |
| 815 } // namespace net | 818 } // namespace net |
| OLD | NEW |