| 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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 if (base::android::BuildInfo::GetInstance()->sdk_int() < | 342 if (base::android::BuildInfo::GetInstance()->sdk_int() < |
| 343 base::android::SDK_VERSION_LOLLIPOP) { | 343 base::android::SDK_VERSION_LOLLIPOP) { |
| 344 return ERR_NOT_IMPLEMENTED; | 344 return ERR_NOT_IMPLEMENTED; |
| 345 } | 345 } |
| 346 // NOTE(pauljensen): This does rely on Android implementation details, but | 346 // NOTE(pauljensen): This does rely on Android implementation details, but |
| 347 // these details are unlikely to change. | 347 // these details are unlikely to change. |
| 348 typedef int (*SetNetworkForSocket)(unsigned netId, int socketFd); | 348 typedef int (*SetNetworkForSocket)(unsigned netId, int socketFd); |
| 349 static SetNetworkForSocket setNetworkForSocket; | 349 static SetNetworkForSocket setNetworkForSocket; |
| 350 // This is racy, but all racers should come out with the same answer so it | 350 // This is racy, but all racers should come out with the same answer so it |
| 351 // shouldn't matter. | 351 // shouldn't matter. |
| 352 if (setNetworkForSocket == nullptr) { | 352 if (!setNetworkForSocket) { |
| 353 // Android's netd client library should always be loaded in our address | 353 // Android's netd client library should always be loaded in our address |
| 354 // space as it shims libc functions like connect(). | 354 // space as it shims libc functions like connect(). |
| 355 base::FilePath file(base::FilePath::FromUTF16Unsafe( | 355 base::FilePath file(base::GetNativeLibraryName("netd_client")); |
| 356 base::GetNativeLibraryName(base::ASCIIToUTF16("netd_client")))); | |
| 357 base::NativeLibrary lib = base::LoadNativeLibrary(file, nullptr); | 356 base::NativeLibrary lib = base::LoadNativeLibrary(file, nullptr); |
| 358 setNetworkForSocket = reinterpret_cast<SetNetworkForSocket>( | 357 setNetworkForSocket = reinterpret_cast<SetNetworkForSocket>( |
| 359 base::GetFunctionPointerFromNativeLibrary(lib, "setNetworkForSocket")); | 358 base::GetFunctionPointerFromNativeLibrary(lib, "setNetworkForSocket")); |
| 360 } | 359 } |
| 361 if (setNetworkForSocket == nullptr) | 360 if (!setNetworkForSocket) |
| 362 return ERR_NOT_IMPLEMENTED; | 361 return ERR_NOT_IMPLEMENTED; |
| 363 int rv = setNetworkForSocket(network, socket_); | 362 int rv = setNetworkForSocket(network, socket_); |
| 364 // If |network| has since disconnected, |rv| will be ENONET. Surface this as | 363 // If |network| has since disconnected, |rv| will be ENONET. Surface this as |
| 365 // ERR_NETWORK_CHANGED, rather than MapSystemError(ENONET) which gives back | 364 // ERR_NETWORK_CHANGED, rather than MapSystemError(ENONET) which gives back |
| 366 // the less descriptive ERR_FAILED. | 365 // the less descriptive ERR_FAILED. |
| 367 if (rv == ENONET) | 366 if (rv == ENONET) |
| 368 return ERR_NETWORK_CHANGED; | 367 return ERR_NETWORK_CHANGED; |
| 369 if (rv == 0) | 368 if (rv == 0) |
| 370 bound_network_ = network; | 369 bound_network_ = network; |
| 371 return MapSystemError(rv); | 370 return MapSystemError(rv); |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 return MapSystemError(errno); | 806 return MapSystemError(errno); |
| 808 | 807 |
| 809 return OK; | 808 return OK; |
| 810 } | 809 } |
| 811 | 810 |
| 812 void UDPSocketPosix::DetachFromThread() { | 811 void UDPSocketPosix::DetachFromThread() { |
| 813 base::NonThreadSafe::DetachFromThread(); | 812 base::NonThreadSafe::DetachFromThread(); |
| 814 } | 813 } |
| 815 | 814 |
| 816 } // namespace net | 815 } // namespace net |
| OLD | NEW |