OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 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 #include "webrtc/p2p/base/basicpacketsocketfactory.h" | 11 #include "webrtc/p2p/base/basicpacketsocketfactory.h" |
12 | 12 |
13 #include "webrtc/p2p/base/asyncstuntcpsocket.h" | 13 #include "webrtc/p2p/base/asyncstuntcpsocket.h" |
14 #include "webrtc/p2p/base/stun.h" | 14 #include "webrtc/p2p/base/stun.h" |
15 #include "webrtc/base/asynctcpsocket.h" | 15 #include "webrtc/base/asynctcpsocket.h" |
16 #include "webrtc/base/asyncudpsocket.h" | 16 #include "webrtc/base/asyncudpsocket.h" |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/base/nethelpers.h" | 18 #include "webrtc/base/nethelpers.h" |
19 #include "webrtc/base/physicalsocketserver.h" | 19 #include "webrtc/base/physicalsocketserver.h" |
20 #include "webrtc/base/scoped_ptr.h" | 20 #include "webrtc/base/scoped_ptr.h" |
21 #include "webrtc/base/socketadapters.h" | 21 #include "webrtc/base/socketadapters.h" |
22 #include "webrtc/base/ssladapter.h" | 22 #include "webrtc/base/ssladapter.h" |
23 #include "webrtc/base/thread.h" | 23 #include "webrtc/base/thread.h" |
| 24 #include "webrtc/base/network.h" |
24 | 25 |
25 namespace rtc { | 26 namespace rtc { |
26 | 27 |
27 BasicPacketSocketFactory::BasicPacketSocketFactory() | 28 BasicPacketSocketFactory::BasicPacketSocketFactory() |
28 : thread_(Thread::Current()), | 29 : thread_(Thread::Current()), |
29 socket_factory_(NULL) { | 30 socket_factory_(NULL) { |
30 } | 31 } |
31 | 32 |
32 BasicPacketSocketFactory::BasicPacketSocketFactory(Thread* thread) | 33 BasicPacketSocketFactory::BasicPacketSocketFactory(Thread* thread) |
33 : thread_(thread), | 34 : thread_(thread), |
34 socket_factory_(NULL) { | 35 socket_factory_(NULL) { |
35 } | 36 } |
36 | 37 |
37 BasicPacketSocketFactory::BasicPacketSocketFactory( | 38 BasicPacketSocketFactory::BasicPacketSocketFactory( |
38 SocketFactory* socket_factory) | 39 SocketFactory* socket_factory) |
39 : thread_(NULL), | 40 : thread_(NULL), |
40 socket_factory_(socket_factory) { | 41 socket_factory_(socket_factory) { |
41 } | 42 } |
42 | 43 |
43 BasicPacketSocketFactory::~BasicPacketSocketFactory() { | 44 BasicPacketSocketFactory::~BasicPacketSocketFactory() { |
44 } | 45 } |
45 | 46 |
46 AsyncPacketSocket* BasicPacketSocketFactory::CreateUdpSocket( | 47 AsyncPacketSocket* BasicPacketSocketFactory::CreateUdpSocket( |
47 const SocketAddress& address, | 48 const SocketAddress& address, |
48 uint16_t min_port, | 49 uint16_t min_port, |
49 uint16_t max_port) { | 50 uint16_t max_port) { |
| 51 return CreateUdpSocket(address, min_port, max_port, nullptr); |
| 52 } |
| 53 |
| 54 AsyncPacketSocket* BasicPacketSocketFactory::CreateUdpSocket( |
| 55 const SocketAddress& address, |
| 56 uint16_t min_port, |
| 57 uint16_t max_port, |
| 58 const Network* network) { |
50 // UDP sockets are simple. | 59 // UDP sockets are simple. |
51 rtc::AsyncSocket* socket = | 60 rtc::AsyncSocket* socket = |
52 socket_factory()->CreateAsyncSocket( | 61 socket_factory()->CreateAsyncSocket( |
53 address.family(), SOCK_DGRAM); | 62 address.family(), SOCK_DGRAM); |
54 if (!socket) { | 63 if (!socket) { |
55 return NULL; | 64 return NULL; |
56 } | 65 } |
| 66 if (network != nullptr && network->handle()) { |
| 67 LOG(LS_INFO) << "Bind network handle XXX "<< network->handle(); |
| 68 int res = socket->BindToNetwork(network->handle()); |
| 69 LOG(LS_INFO) << "Bind network handle XXX "<< network->handle() <<" result "<
< res; |
| 70 } |
57 if (BindSocket(socket, address, min_port, max_port) < 0) { | 71 if (BindSocket(socket, address, min_port, max_port) < 0) { |
58 LOG(LS_ERROR) << "UDP bind failed with error " | 72 LOG(LS_ERROR) << "UDP bind failed with error " |
59 << socket->GetError(); | 73 << socket->GetError(); |
60 delete socket; | 74 delete socket; |
61 return NULL; | 75 return NULL; |
62 } | 76 } |
63 return new rtc::AsyncUDPSocket(socket); | 77 return new rtc::AsyncUDPSocket(socket); |
64 } | 78 } |
65 | 79 |
66 AsyncPacketSocket* BasicPacketSocketFactory::CreateServerTcpSocket( | 80 AsyncPacketSocket* BasicPacketSocketFactory::CreateServerTcpSocket( |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 SocketFactory* BasicPacketSocketFactory::socket_factory() { | 214 SocketFactory* BasicPacketSocketFactory::socket_factory() { |
201 if (thread_) { | 215 if (thread_) { |
202 ASSERT(thread_ == Thread::Current()); | 216 ASSERT(thread_ == Thread::Current()); |
203 return thread_->socketserver(); | 217 return thread_->socketserver(); |
204 } else { | 218 } else { |
205 return socket_factory_; | 219 return socket_factory_; |
206 } | 220 } |
207 } | 221 } |
208 | 222 |
209 } // namespace rtc | 223 } // namespace rtc |
OLD | NEW |