OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "remoting/protocol/chromium_socket_factory.h" | 5 #include "remoting/protocol/chromium_socket_factory.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
10 #include "jingle/glue/utils.h" | 13 #include "jingle/glue/utils.h" |
11 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
12 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
13 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
14 #include "net/udp/udp_server_socket.h" | 17 #include "net/udp/udp_server_socket.h" |
15 #include "remoting/protocol/socket_util.h" | 18 #include "remoting/protocol/socket_util.h" |
16 #include "third_party/webrtc/base/asyncpacketsocket.h" | 19 #include "third_party/webrtc/base/asyncpacketsocket.h" |
17 #include "third_party/webrtc/base/nethelpers.h" | 20 #include "third_party/webrtc/base/nethelpers.h" |
18 | 21 |
(...skipping 10 matching lines...) Expand all Loading... |
29 // Pepper's UDP API can handle it. This maximum should never be | 32 // Pepper's UDP API can handle it. This maximum should never be |
30 // reached under normal conditions. | 33 // reached under normal conditions. |
31 const int kMaxSendBufferSize = 256 * 1024; | 34 const int kMaxSendBufferSize = 256 * 1024; |
32 | 35 |
33 class UdpPacketSocket : public rtc::AsyncPacketSocket { | 36 class UdpPacketSocket : public rtc::AsyncPacketSocket { |
34 public: | 37 public: |
35 UdpPacketSocket(); | 38 UdpPacketSocket(); |
36 ~UdpPacketSocket() override; | 39 ~UdpPacketSocket() override; |
37 | 40 |
38 bool Init(const rtc::SocketAddress& local_address, | 41 bool Init(const rtc::SocketAddress& local_address, |
39 uint16 min_port, uint16 max_port); | 42 uint16_t min_port, |
| 43 uint16_t max_port); |
40 | 44 |
41 // rtc::AsyncPacketSocket interface. | 45 // rtc::AsyncPacketSocket interface. |
42 rtc::SocketAddress GetLocalAddress() const override; | 46 rtc::SocketAddress GetLocalAddress() const override; |
43 rtc::SocketAddress GetRemoteAddress() const override; | 47 rtc::SocketAddress GetRemoteAddress() const override; |
44 int Send(const void* data, | 48 int Send(const void* data, |
45 size_t data_size, | 49 size_t data_size, |
46 const rtc::PacketOptions& options) override; | 50 const rtc::PacketOptions& options) override; |
47 int SendTo(const void* data, | 51 int SendTo(const void* data, |
48 size_t data_size, | 52 size_t data_size, |
49 const rtc::SocketAddress& address, | 53 const rtc::SocketAddress& address, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 error_(0), | 112 error_(0), |
109 send_pending_(false), | 113 send_pending_(false), |
110 send_queue_size_(0) { | 114 send_queue_size_(0) { |
111 } | 115 } |
112 | 116 |
113 UdpPacketSocket::~UdpPacketSocket() { | 117 UdpPacketSocket::~UdpPacketSocket() { |
114 Close(); | 118 Close(); |
115 } | 119 } |
116 | 120 |
117 bool UdpPacketSocket::Init(const rtc::SocketAddress& local_address, | 121 bool UdpPacketSocket::Init(const rtc::SocketAddress& local_address, |
118 uint16 min_port, uint16 max_port) { | 122 uint16_t min_port, |
| 123 uint16_t max_port) { |
119 net::IPEndPoint local_endpoint; | 124 net::IPEndPoint local_endpoint; |
120 if (!jingle_glue::SocketAddressToIPEndPoint( | 125 if (!jingle_glue::SocketAddressToIPEndPoint( |
121 local_address, &local_endpoint)) { | 126 local_address, &local_endpoint)) { |
122 return false; | 127 return false; |
123 } | 128 } |
124 | 129 |
125 for (uint32 port = min_port; port <= max_port; ++port) { | 130 for (uint32_t port = min_port; port <= max_port; ++port) { |
126 socket_.reset(new net::UDPServerSocket(nullptr, net::NetLog::Source())); | 131 socket_.reset(new net::UDPServerSocket(nullptr, net::NetLog::Source())); |
127 int result = socket_->Listen( | 132 int result = socket_->Listen( |
128 net::IPEndPoint(local_endpoint.address(), static_cast<uint16>(port))); | 133 net::IPEndPoint(local_endpoint.address(), static_cast<uint16_t>(port))); |
129 if (result == net::OK) { | 134 if (result == net::OK) { |
130 break; | 135 break; |
131 } else { | 136 } else { |
132 socket_.reset(); | 137 socket_.reset(); |
133 } | 138 } |
134 } | 139 } |
135 | 140 |
136 if (!socket_.get()) { | 141 if (!socket_.get()) { |
137 // Failed to bind the socket. | 142 // Failed to bind the socket. |
138 return false; | 143 return false; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 358 |
354 } // namespace | 359 } // namespace |
355 | 360 |
356 ChromiumPacketSocketFactory::ChromiumPacketSocketFactory() { | 361 ChromiumPacketSocketFactory::ChromiumPacketSocketFactory() { |
357 } | 362 } |
358 | 363 |
359 ChromiumPacketSocketFactory::~ChromiumPacketSocketFactory() { | 364 ChromiumPacketSocketFactory::~ChromiumPacketSocketFactory() { |
360 } | 365 } |
361 | 366 |
362 rtc::AsyncPacketSocket* ChromiumPacketSocketFactory::CreateUdpSocket( | 367 rtc::AsyncPacketSocket* ChromiumPacketSocketFactory::CreateUdpSocket( |
363 const rtc::SocketAddress& local_address, | 368 const rtc::SocketAddress& local_address, |
364 uint16 min_port, uint16 max_port) { | 369 uint16_t min_port, |
| 370 uint16_t max_port) { |
365 scoped_ptr<UdpPacketSocket> result(new UdpPacketSocket()); | 371 scoped_ptr<UdpPacketSocket> result(new UdpPacketSocket()); |
366 if (!result->Init(local_address, min_port, max_port)) | 372 if (!result->Init(local_address, min_port, max_port)) |
367 return nullptr; | 373 return nullptr; |
368 return result.release(); | 374 return result.release(); |
369 } | 375 } |
370 | 376 |
371 rtc::AsyncPacketSocket* | 377 rtc::AsyncPacketSocket* ChromiumPacketSocketFactory::CreateServerTcpSocket( |
372 ChromiumPacketSocketFactory::CreateServerTcpSocket( | |
373 const rtc::SocketAddress& local_address, | 378 const rtc::SocketAddress& local_address, |
374 uint16 min_port, uint16 max_port, | 379 uint16_t min_port, |
| 380 uint16_t max_port, |
375 int opts) { | 381 int opts) { |
376 // We don't use TCP sockets for remoting connections. | 382 // We don't use TCP sockets for remoting connections. |
377 NOTIMPLEMENTED(); | 383 NOTIMPLEMENTED(); |
378 return nullptr; | 384 return nullptr; |
379 } | 385 } |
380 | 386 |
381 rtc::AsyncPacketSocket* | 387 rtc::AsyncPacketSocket* |
382 ChromiumPacketSocketFactory::CreateClientTcpSocket( | 388 ChromiumPacketSocketFactory::CreateClientTcpSocket( |
383 const rtc::SocketAddress& local_address, | 389 const rtc::SocketAddress& local_address, |
384 const rtc::SocketAddress& remote_address, | 390 const rtc::SocketAddress& remote_address, |
385 const rtc::ProxyInfo& proxy_info, | 391 const rtc::ProxyInfo& proxy_info, |
386 const std::string& user_agent, | 392 const std::string& user_agent, |
387 int opts) { | 393 int opts) { |
388 // We don't use TCP sockets for remoting connections. | 394 // We don't use TCP sockets for remoting connections. |
389 NOTREACHED(); | 395 NOTREACHED(); |
390 return nullptr; | 396 return nullptr; |
391 } | 397 } |
392 | 398 |
393 rtc::AsyncResolverInterface* | 399 rtc::AsyncResolverInterface* |
394 ChromiumPacketSocketFactory::CreateAsyncResolver() { | 400 ChromiumPacketSocketFactory::CreateAsyncResolver() { |
395 return new rtc::AsyncResolver(); | 401 return new rtc::AsyncResolver(); |
396 } | 402 } |
397 | 403 |
398 } // namespace protocol | 404 } // namespace protocol |
399 } // namespace remoting | 405 } // namespace remoting |
OLD | NEW |