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

Side by Side Diff: webrtc/base/physicalsocketserver.cc

Issue 1535943004: Multi-networking with Android L. Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years 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 unified diff | Download patch
« no previous file with comments | « webrtc/base/networkmonitor.cc ('k') | webrtc/base/socket.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #if defined(_MSC_VER) && _MSC_VER < 1300 11 #if defined(_MSC_VER) && _MSC_VER < 1300
12 #pragma warning(disable:4786) 12 #pragma warning(disable:4786)
13 #endif 13 #endif
14 14
15 #include <assert.h> 15 #include <assert.h>
16 16
17 #include <dlfcn.h>
18
17 #ifdef MEMORY_SANITIZER 19 #ifdef MEMORY_SANITIZER
18 #include <sanitizer/msan_interface.h> 20 #include <sanitizer/msan_interface.h>
19 #endif 21 #endif
20 22
21 #if defined(WEBRTC_POSIX) 23 #if defined(WEBRTC_POSIX)
22 #include <string.h> 24 #include <string.h>
23 #include <errno.h> 25 #include <errno.h>
24 #include <fcntl.h> 26 #include <fcntl.h>
25 #include <sys/time.h> 27 #include <sys/time.h>
26 #include <sys/select.h> 28 #include <sys/select.h>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 68, // Official minimum 92 68, // Official minimum
91 0, // End of list marker 93 0, // End of list marker
92 }; 94 };
93 95
94 static const int IP_HEADER_SIZE = 20u; 96 static const int IP_HEADER_SIZE = 20u;
95 static const int IPV6_HEADER_SIZE = 40u; 97 static const int IPV6_HEADER_SIZE = 40u;
96 static const int ICMP_HEADER_SIZE = 8u; 98 static const int ICMP_HEADER_SIZE = 8u;
97 static const int ICMP_PING_TIMEOUT_MILLIS = 10000u; 99 static const int ICMP_PING_TIMEOUT_MILLIS = 10000u;
98 #endif 100 #endif
99 101
102 static const int ERR_NOT_IMPLEMENTED = -11;
103 static const int ERR_NETWORK_CHANGED = -21;
104 static const int ERR_FAILED = -1;
105 static const uint32_t INVALID_NETWORK_HANDLE = 0xFFFFFFFF;
106
100 class PhysicalSocket : public AsyncSocket, public sigslot::has_slots<> { 107 class PhysicalSocket : public AsyncSocket, public sigslot::has_slots<> {
101 public: 108 public:
102 PhysicalSocket(PhysicalSocketServer* ss, SOCKET s = INVALID_SOCKET) 109 PhysicalSocket(PhysicalSocketServer* ss, SOCKET s = INVALID_SOCKET)
103 : ss_(ss), s_(s), enabled_events_(0), error_(0), 110 : ss_(ss), s_(s), enabled_events_(0), error_(0),
104 state_((s == INVALID_SOCKET) ? CS_CLOSED : CS_CONNECTED), 111 state_((s == INVALID_SOCKET) ? CS_CLOSED : CS_CONNECTED),
105 resolver_(NULL) { 112 resolver_(NULL) {
106 #if defined(WEBRTC_WIN) 113 #if defined(WEBRTC_WIN)
107 // EnsureWinsockInit() ensures that winsock is initialized. The default 114 // EnsureWinsockInit() ensures that winsock is initialized. The default
108 // version of this function doesn't do anything because winsock is 115 // version of this function doesn't do anything because winsock is
109 // initialized by constructor of a static object. If neccessary libjingle 116 // initialized by constructor of a static object. If neccessary libjingle
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 UpdateLastError(); 181 UpdateLastError();
175 #if !defined(NDEBUG) 182 #if !defined(NDEBUG)
176 if (0 == err) { 183 if (0 == err) {
177 dbg_addr_ = "Bound @ "; 184 dbg_addr_ = "Bound @ ";
178 dbg_addr_.append(GetLocalAddress().ToString()); 185 dbg_addr_.append(GetLocalAddress().ToString());
179 } 186 }
180 #endif 187 #endif
181 return err; 188 return err;
182 } 189 }
183 190
191 int BindToNetwork(NetworkHandle network) override {
192 LOG(LS_INFO) << "Bind socket " << s_ << " to network " << network;
193 if (network == INVALID_NETWORK_HANDLE)
194 return -1;
195 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
196 // Android prior to Lollipop didn't have support for binding sockets to
197 // networks.
198 // if (base::android::BuildInfo::GetInstance()->sdk_int() <
199 // base::android::SDK_VERSION_LOLLIPOP) {
200 // return ERR_NOT_IMPLEMENTED;
201 //}
202
203 // NOTE: This does rely on Android implementation details, but
204 // these details are unlikely to change.
205 typedef int (*SetNetworkForSocket)(unsigned netId, int socketFd);
206 static SetNetworkForSocket setNetworkForSocket;
207 // This is racy, but all racers should come out with the same answer so it
208 // shouldn't matter.
209 if (setNetworkForSocket == nullptr) {
210 // Android's netd client library should always be loaded in our address
211 // space as it shims libc functions like connect().
212 const std::string net_library_path = "libnetd_client.so";
213 LOG(LS_ERROR) << "Load Library " << net_library_path;
214 void* lib = dlopen(net_library_path.c_str(), RTLD_LAZY);
215 if (lib == nullptr) {
216 LOG(LS_ERROR) << "Library " << net_library_path << " not found!";
217 return ERR_NOT_IMPLEMENTED;
218 }
219 setNetworkForSocket = reinterpret_cast<SetNetworkForSocket>(
220 dlsym(lib, "setNetworkForSocket"));
221 }
222 if (setNetworkForSocket == nullptr) {
223 LOG(LS_ERROR) << "symbole not found ";
224 return ERR_NOT_IMPLEMENTED;
225 }
226 int rv = setNetworkForSocket(network, s_);
227 // If |network| has since disconnected, |rv| will be ENONET. Surface this
228 // as
229 // ERR_NETWORK_CHANGED, rather than MapSystemError(ENONET) which gives back
230 // the less descriptive ERR_FAILED.
231 if (rv == ENONET)
232 return ERR_NETWORK_CHANGED;
233 return ERR_FAILED;
234 #else
235 return ERR_NOT_IMPLEMENTED;
236 #endif
237 }
238
184 int Connect(const SocketAddress& addr) override { 239 int Connect(const SocketAddress& addr) override {
185 // TODO: Implicit creation is required to reconnect... 240 // TODO: Implicit creation is required to reconnect...
186 // ...but should we make it more explicit? 241 // ...but should we make it more explicit?
187 if (state_ != CS_CLOSED) { 242 if (state_ != CS_CLOSED) {
188 SetError(EALREADY); 243 SetError(EALREADY);
189 return SOCKET_ERROR; 244 return SOCKET_ERROR;
190 } 245 }
191 if (addr.IsUnresolvedIP()) { 246 if (addr.IsUnresolvedIP()) {
192 LOG(LS_VERBOSE) << "Resolving addr in PhysicalSocket::Connect"; 247 LOG(LS_VERBOSE) << "Resolving addr in PhysicalSocket::Connect";
193 resolver_ = new AsyncResolver(); 248 resolver_ = new AsyncResolver();
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 1186
1132 state_ = CS_CLOSED; 1187 state_ = CS_CLOSED;
1133 signal_close_ = false; 1188 signal_close_ = false;
1134 SignalCloseEvent(this, signal_err_); 1189 SignalCloseEvent(this, signal_err_);
1135 return true; 1190 return true;
1136 } 1191 }
1137 }; 1192 };
1138 1193
1139 int SocketDispatcher::next_id_ = 0; 1194 int SocketDispatcher::next_id_ = 0;
1140 1195
1141 #endif // WEBRTC_WIN 1196 #endif // WEBRTC_WIN
1142 1197
1143 // Sets the value of a boolean value to false when signaled. 1198 // Sets the value of a boolean value to false when signaled.
1144 class Signaler : public EventDispatcher { 1199 class Signaler : public EventDispatcher {
1145 public: 1200 public:
1146 Signaler(PhysicalSocketServer* ss, bool* pf) 1201 Signaler(PhysicalSocketServer* ss, bool* pf)
1147 : EventDispatcher(ss), pf_(pf) { 1202 : EventDispatcher(ss), pf_(pf) {
1148 } 1203 }
1149 ~Signaler() override { } 1204 ~Signaler() override { }
1150 1205
1151 void OnEvent(uint32_t ff, int err) override { 1206 void OnEvent(uint32_t ff, int err) override {
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 break; 1680 break;
1626 cmsElapsed = TimeSince(msStart); 1681 cmsElapsed = TimeSince(msStart);
1627 if ((cmsWait != kForever) && (cmsElapsed >= cmsWait)) { 1682 if ((cmsWait != kForever) && (cmsElapsed >= cmsWait)) {
1628 break; 1683 break;
1629 } 1684 }
1630 } 1685 }
1631 1686
1632 // Done 1687 // Done
1633 return true; 1688 return true;
1634 } 1689 }
1635 #endif // WEBRTC_WIN 1690 #endif // WEBRTC_WIN
1636 1691
1637 } // namespace rtc 1692 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/networkmonitor.cc ('k') | webrtc/base/socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698