OLD | NEW |
---|---|
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 #include "webrtc/base/physicalsocketserver.h" | |
10 | 11 |
11 #if defined(_MSC_VER) && _MSC_VER < 1300 | 12 #if defined(_MSC_VER) && _MSC_VER < 1300 |
12 #pragma warning(disable:4786) | 13 #pragma warning(disable:4786) |
13 #endif | 14 #endif |
14 | 15 |
15 #include <assert.h> | 16 #include <assert.h> |
16 | 17 |
17 #ifdef MEMORY_SANITIZER | 18 #ifdef MEMORY_SANITIZER |
18 #include <sanitizer/msan_interface.h> | 19 #include <sanitizer/msan_interface.h> |
19 #endif | 20 #endif |
(...skipping 17 matching lines...) Expand all Loading... | |
37 #endif | 38 #endif |
38 | 39 |
39 #include <algorithm> | 40 #include <algorithm> |
40 #include <map> | 41 #include <map> |
41 | 42 |
42 #include "webrtc/base/arraysize.h" | 43 #include "webrtc/base/arraysize.h" |
43 #include "webrtc/base/basictypes.h" | 44 #include "webrtc/base/basictypes.h" |
44 #include "webrtc/base/byteorder.h" | 45 #include "webrtc/base/byteorder.h" |
45 #include "webrtc/base/common.h" | 46 #include "webrtc/base/common.h" |
46 #include "webrtc/base/logging.h" | 47 #include "webrtc/base/logging.h" |
47 #include "webrtc/base/physicalsocketserver.h" | |
48 #include "webrtc/base/timeutils.h" | 48 #include "webrtc/base/timeutils.h" |
49 #include "webrtc/base/winping.h" | 49 #include "webrtc/base/winping.h" |
50 #include "webrtc/base/win32socketinit.h" | 50 #include "webrtc/base/win32socketinit.h" |
51 | 51 |
52 // stm: this will tell us if we are on OSX | 52 // stm: this will tell us if we are on OSX |
53 #ifdef HAVE_CONFIG_H | 53 #ifdef HAVE_CONFIG_H |
54 #include "config.h" | 54 #include "config.h" |
55 #endif | 55 #endif |
56 | 56 |
57 #if defined(WEBRTC_POSIX) | 57 #if defined(WEBRTC_POSIX) |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 size_t len = bind_addr.ToSockAddrStorage(&addr_storage); | 167 size_t len = bind_addr.ToSockAddrStorage(&addr_storage); |
168 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage); | 168 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage); |
169 int err = ::bind(s_, addr, static_cast<int>(len)); | 169 int err = ::bind(s_, addr, static_cast<int>(len)); |
170 UpdateLastError(); | 170 UpdateLastError(); |
171 #if !defined(NDEBUG) | 171 #if !defined(NDEBUG) |
172 if (0 == err) { | 172 if (0 == err) { |
173 dbg_addr_ = "Bound @ "; | 173 dbg_addr_ = "Bound @ "; |
174 dbg_addr_.append(GetLocalAddress().ToString()); | 174 dbg_addr_.append(GetLocalAddress().ToString()); |
175 } | 175 } |
176 #endif | 176 #endif |
177 if (ss_->network_binder()) { | |
178 int result = | |
179 ss_->network_binder()->BindSocketToNetwork(s_, bind_addr.ipaddr()); | |
180 if (result < 0) { | |
181 LOG(LS_INFO) << "Binding socket to network address " | |
182 << bind_addr.ipaddr().ToString() << " result " << result; | |
183 } | |
184 } | |
177 return err; | 185 return err; |
178 } | 186 } |
179 | 187 |
180 int PhysicalSocket::Connect(const SocketAddress& addr) { | 188 int PhysicalSocket::Connect(const SocketAddress& addr) { |
181 // TODO(pthatcher): Implicit creation is required to reconnect... | 189 // TODO(pthatcher): Implicit creation is required to reconnect... |
182 // ...but should we make it more explicit? | 190 // ...but should we make it more explicit? |
183 if (state_ != CS_CLOSED) { | 191 if (state_ != CS_CLOSED) { |
184 SetError(EALREADY); | 192 SetError(EALREADY); |
185 return SOCKET_ERROR; | 193 return SOCKET_ERROR; |
186 } | 194 } |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1102 virtual SOCKET GetSocket() { | 1110 virtual SOCKET GetSocket() { |
1103 return INVALID_SOCKET; | 1111 return INVALID_SOCKET; |
1104 } | 1112 } |
1105 | 1113 |
1106 virtual bool CheckSignalClose() { return false; } | 1114 virtual bool CheckSignalClose() { return false; } |
1107 | 1115 |
1108 private: | 1116 private: |
1109 PhysicalSocketServer* ss_; | 1117 PhysicalSocketServer* ss_; |
1110 WSAEVENT hev_; | 1118 WSAEVENT hev_; |
1111 }; | 1119 }; |
1112 #endif // WEBRTC_WIN | 1120 #endif // WEBRTC_WIN |
1113 | 1121 |
1114 // Sets the value of a boolean value to false when signaled. | 1122 // Sets the value of a boolean value to false when signaled. |
1115 class Signaler : public EventDispatcher { | 1123 class Signaler : public EventDispatcher { |
1116 public: | 1124 public: |
1117 Signaler(PhysicalSocketServer* ss, bool* pf) | 1125 Signaler(PhysicalSocketServer* ss, bool* pf) |
1118 : EventDispatcher(ss), pf_(pf) { | 1126 : EventDispatcher(ss), pf_(pf) { |
1119 } | 1127 } |
1120 ~Signaler() override { } | 1128 ~Signaler() override { } |
1121 | 1129 |
1122 void OnEvent(uint32_t ff, int err) override { | 1130 void OnEvent(uint32_t ff, int err) override { |
(...skipping 21 matching lines...) Expand all Loading... | |
1144 signal_dispatcher_.reset(); | 1152 signal_dispatcher_.reset(); |
1145 #endif | 1153 #endif |
1146 delete signal_wakeup_; | 1154 delete signal_wakeup_; |
1147 ASSERT(dispatchers_.empty()); | 1155 ASSERT(dispatchers_.empty()); |
1148 } | 1156 } |
1149 | 1157 |
1150 void PhysicalSocketServer::WakeUp() { | 1158 void PhysicalSocketServer::WakeUp() { |
1151 signal_wakeup_->Signal(); | 1159 signal_wakeup_->Signal(); |
1152 } | 1160 } |
1153 | 1161 |
1162 void PhysicalSocketServer::MaybeSetNetworkBinder() { | |
1163 if (NetworkMonitorFactory::GetFactory()) { | |
1164 network_binder_ = | |
1165 NetworkMonitorFactory::GetFactory()->GetOrCreateNetworkMonitor(); | |
1166 } | |
pthatcher1
2016/01/14 20:07:24
I'm not sure if this is the best way to get it con
honghaiz3
2016/01/15 01:00:38
Removed this. Set Networkbinder from the network m
| |
1167 } | |
1168 | |
1154 Socket* PhysicalSocketServer::CreateSocket(int type) { | 1169 Socket* PhysicalSocketServer::CreateSocket(int type) { |
1155 return CreateSocket(AF_INET, type); | 1170 return CreateSocket(AF_INET, type); |
1156 } | 1171 } |
1157 | 1172 |
1158 Socket* PhysicalSocketServer::CreateSocket(int family, int type) { | 1173 Socket* PhysicalSocketServer::CreateSocket(int family, int type) { |
1159 PhysicalSocket* socket = new PhysicalSocket(this); | 1174 PhysicalSocket* socket = new PhysicalSocket(this); |
1160 if (socket->Create(family, type)) { | 1175 if (socket->Create(family, type)) { |
1161 return socket; | 1176 return socket; |
1162 } else { | 1177 } else { |
1163 delete socket; | 1178 delete socket; |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1596 break; | 1611 break; |
1597 cmsElapsed = TimeSince(msStart); | 1612 cmsElapsed = TimeSince(msStart); |
1598 if ((cmsWait != kForever) && (cmsElapsed >= cmsWait)) { | 1613 if ((cmsWait != kForever) && (cmsElapsed >= cmsWait)) { |
1599 break; | 1614 break; |
1600 } | 1615 } |
1601 } | 1616 } |
1602 | 1617 |
1603 // Done | 1618 // Done |
1604 return true; | 1619 return true; |
1605 } | 1620 } |
1606 #endif // WEBRTC_WIN | 1621 #endif // WEBRTC_WIN |
1607 | 1622 |
1608 } // namespace rtc | 1623 } // namespace rtc |
OLD | NEW |