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 |
(...skipping 26 matching lines...) Expand all Loading... |
37 BasicPacketSocketFactory::BasicPacketSocketFactory( | 37 BasicPacketSocketFactory::BasicPacketSocketFactory( |
38 SocketFactory* socket_factory) | 38 SocketFactory* socket_factory) |
39 : thread_(NULL), | 39 : thread_(NULL), |
40 socket_factory_(socket_factory) { | 40 socket_factory_(socket_factory) { |
41 } | 41 } |
42 | 42 |
43 BasicPacketSocketFactory::~BasicPacketSocketFactory() { | 43 BasicPacketSocketFactory::~BasicPacketSocketFactory() { |
44 } | 44 } |
45 | 45 |
46 AsyncPacketSocket* BasicPacketSocketFactory::CreateUdpSocket( | 46 AsyncPacketSocket* BasicPacketSocketFactory::CreateUdpSocket( |
47 const SocketAddress& address, uint16 min_port, uint16 max_port) { | 47 const SocketAddress& address, |
| 48 uint16_t min_port, |
| 49 uint16_t max_port) { |
48 // UDP sockets are simple. | 50 // UDP sockets are simple. |
49 rtc::AsyncSocket* socket = | 51 rtc::AsyncSocket* socket = |
50 socket_factory()->CreateAsyncSocket( | 52 socket_factory()->CreateAsyncSocket( |
51 address.family(), SOCK_DGRAM); | 53 address.family(), SOCK_DGRAM); |
52 if (!socket) { | 54 if (!socket) { |
53 return NULL; | 55 return NULL; |
54 } | 56 } |
55 if (BindSocket(socket, address, min_port, max_port) < 0) { | 57 if (BindSocket(socket, address, min_port, max_port) < 0) { |
56 LOG(LS_ERROR) << "UDP bind failed with error " | 58 LOG(LS_ERROR) << "UDP bind failed with error " |
57 << socket->GetError(); | 59 << socket->GetError(); |
58 delete socket; | 60 delete socket; |
59 return NULL; | 61 return NULL; |
60 } | 62 } |
61 return new rtc::AsyncUDPSocket(socket); | 63 return new rtc::AsyncUDPSocket(socket); |
62 } | 64 } |
63 | 65 |
64 AsyncPacketSocket* BasicPacketSocketFactory::CreateServerTcpSocket( | 66 AsyncPacketSocket* BasicPacketSocketFactory::CreateServerTcpSocket( |
65 const SocketAddress& local_address, uint16 min_port, uint16 max_port, | 67 const SocketAddress& local_address, |
| 68 uint16_t min_port, |
| 69 uint16_t max_port, |
66 int opts) { | 70 int opts) { |
67 | |
68 // Fail if TLS is required. | 71 // Fail if TLS is required. |
69 if (opts & PacketSocketFactory::OPT_TLS) { | 72 if (opts & PacketSocketFactory::OPT_TLS) { |
70 LOG(LS_ERROR) << "TLS support currently is not available."; | 73 LOG(LS_ERROR) << "TLS support currently is not available."; |
71 return NULL; | 74 return NULL; |
72 } | 75 } |
73 | 76 |
74 rtc::AsyncSocket* socket = | 77 rtc::AsyncSocket* socket = |
75 socket_factory()->CreateAsyncSocket(local_address.family(), | 78 socket_factory()->CreateAsyncSocket(local_address.family(), |
76 SOCK_STREAM); | 79 SOCK_STREAM); |
77 if (!socket) { | 80 if (!socket) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // See http://go/gtalktcpnodelayexperiment | 172 // See http://go/gtalktcpnodelayexperiment |
170 tcp_socket->SetOption(rtc::Socket::OPT_NODELAY, 1); | 173 tcp_socket->SetOption(rtc::Socket::OPT_NODELAY, 1); |
171 | 174 |
172 return tcp_socket; | 175 return tcp_socket; |
173 } | 176 } |
174 | 177 |
175 AsyncResolverInterface* BasicPacketSocketFactory::CreateAsyncResolver() { | 178 AsyncResolverInterface* BasicPacketSocketFactory::CreateAsyncResolver() { |
176 return new rtc::AsyncResolver(); | 179 return new rtc::AsyncResolver(); |
177 } | 180 } |
178 | 181 |
179 int BasicPacketSocketFactory::BindSocket( | 182 int BasicPacketSocketFactory::BindSocket(AsyncSocket* socket, |
180 AsyncSocket* socket, const SocketAddress& local_address, | 183 const SocketAddress& local_address, |
181 uint16 min_port, uint16 max_port) { | 184 uint16_t min_port, |
| 185 uint16_t max_port) { |
182 int ret = -1; | 186 int ret = -1; |
183 if (min_port == 0 && max_port == 0) { | 187 if (min_port == 0 && max_port == 0) { |
184 // If there's no port range, let the OS pick a port for us. | 188 // If there's no port range, let the OS pick a port for us. |
185 ret = socket->Bind(local_address); | 189 ret = socket->Bind(local_address); |
186 } else { | 190 } else { |
187 // Otherwise, try to find a port in the provided range. | 191 // Otherwise, try to find a port in the provided range. |
188 for (int port = min_port; ret < 0 && port <= max_port; ++port) { | 192 for (int port = min_port; ret < 0 && port <= max_port; ++port) { |
189 ret = socket->Bind(rtc::SocketAddress(local_address.ipaddr(), | 193 ret = socket->Bind(rtc::SocketAddress(local_address.ipaddr(), |
190 port)); | 194 port)); |
191 } | 195 } |
192 } | 196 } |
193 return ret; | 197 return ret; |
194 } | 198 } |
195 | 199 |
196 SocketFactory* BasicPacketSocketFactory::socket_factory() { | 200 SocketFactory* BasicPacketSocketFactory::socket_factory() { |
197 if (thread_) { | 201 if (thread_) { |
198 ASSERT(thread_ == Thread::Current()); | 202 ASSERT(thread_ == Thread::Current()); |
199 return thread_->socketserver(); | 203 return thread_->socketserver(); |
200 } else { | 204 } else { |
201 return socket_factory_; | 205 return socket_factory_; |
202 } | 206 } |
203 } | 207 } |
204 | 208 |
205 } // namespace rtc | 209 } // namespace rtc |
OLD | NEW |