OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/jingle_glue/chromium_socket_factory.h" | 5 #include "remoting/jingle_glue/chromium_socket_factory.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "jingle/glue/utils.h" | 10 #include "jingle/glue/utils.h" |
11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
12 #include "net/base/ip_endpoint.h" | 12 #include "net/base/ip_endpoint.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/udp/udp_server_socket.h" | 14 #include "net/udp/udp_server_socket.h" |
15 #include "third_party/libjingle/source/talk/base/asyncpacketsocket.h" | 15 #include "third_party/libjingle/source/talk/base/asyncpacketsocket.h" |
16 #include "third_party/libjingle/source/talk/base/asyncresolverinterface.h" | 16 #include "third_party/libjingle/source/talk/base/nethelpers.h" |
17 | 17 |
18 namespace remoting { | 18 namespace remoting { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Size of the buffer to allocate for RecvFrom(). | 22 // Size of the buffer to allocate for RecvFrom(). |
23 const int kReceiveBufferSize = 65536; | 23 const int kReceiveBufferSize = 65536; |
24 | 24 |
25 // Maximum amount of data in the send buffers. This is necessary to | 25 // Maximum amount of data in the send buffers. This is necessary to |
26 // prevent out-of-memory crashes if the caller sends data faster than | 26 // prevent out-of-memory crashes if the caller sends data faster than |
27 // Pepper's UDP API can handle it. This maximum should never be | 27 // Pepper's UDP API can handle it. This maximum should never be |
28 // reached under normal conditions. | 28 // reached under normal conditions. |
29 const int kMaxSendBufferSize = 256 * 1024; | 29 const int kMaxSendBufferSize = 256 * 1024; |
30 | 30 |
31 // Defines set of transient errors. These errors are ignored when we get them | 31 // Defines set of transient errors. These errors are ignored when we get them |
32 // from sendto() calls. | 32 // from sendto() calls. |
33 bool IsTransientError(int error) { | 33 bool IsTransientError(int error) { |
34 return error == net::ERR_ADDRESS_UNREACHABLE || | 34 return error == net::ERR_ADDRESS_UNREACHABLE || |
35 error == net::ERR_ADDRESS_INVALID; | 35 error == net::ERR_ADDRESS_INVALID; |
36 } | 36 } |
37 | 37 |
38 // TODO(lambroslambrou): Move STUN/relay address resolution from | |
39 // PepperPortAllocator to this class. | |
40 class DummyAsyncResolver : public talk_base::AsyncResolverInterface { | |
41 public: | |
42 DummyAsyncResolver() {} | |
43 virtual ~DummyAsyncResolver() {} | |
44 virtual void Start(const talk_base::SocketAddress& addr) OVERRIDE {} | |
45 virtual bool GetResolvedAddress( | |
46 int family, | |
47 talk_base::SocketAddress* addr) const OVERRIDE { | |
48 return false; | |
49 } | |
50 virtual int GetError() const OVERRIDE { | |
51 return 0; | |
52 } | |
53 virtual void Destroy(bool wait) OVERRIDE { | |
54 delete this; | |
55 } | |
56 | |
57 private: | |
58 DISALLOW_COPY_AND_ASSIGN(DummyAsyncResolver); | |
59 }; | |
60 | |
61 class UdpPacketSocket : public talk_base::AsyncPacketSocket { | 38 class UdpPacketSocket : public talk_base::AsyncPacketSocket { |
62 public: | 39 public: |
63 UdpPacketSocket(); | 40 UdpPacketSocket(); |
64 virtual ~UdpPacketSocket(); | 41 virtual ~UdpPacketSocket(); |
65 | 42 |
66 bool Init(const talk_base::SocketAddress& local_address, | 43 bool Init(const talk_base::SocketAddress& local_address, |
67 int min_port, int max_port); | 44 int min_port, int max_port); |
68 | 45 |
69 // talk_base::AsyncPacketSocket interface. | 46 // talk_base::AsyncPacketSocket interface. |
70 virtual talk_base::SocketAddress GetLocalAddress() const OVERRIDE; | 47 virtual talk_base::SocketAddress GetLocalAddress() const OVERRIDE; |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 const talk_base::ProxyInfo& proxy_info, | 368 const talk_base::ProxyInfo& proxy_info, |
392 const std::string& user_agent, | 369 const std::string& user_agent, |
393 int opts) { | 370 int opts) { |
394 // We don't use TCP sockets for remoting connections. | 371 // We don't use TCP sockets for remoting connections. |
395 NOTREACHED(); | 372 NOTREACHED(); |
396 return NULL; | 373 return NULL; |
397 } | 374 } |
398 | 375 |
399 talk_base::AsyncResolverInterface* | 376 talk_base::AsyncResolverInterface* |
400 ChromiumPacketSocketFactory::CreateAsyncResolver() { | 377 ChromiumPacketSocketFactory::CreateAsyncResolver() { |
401 return new DummyAsyncResolver(); | 378 return new talk_base::AsyncResolver(); |
402 } | 379 } |
403 | 380 |
404 } // namespace remoting | 381 } // namespace remoting |
OLD | NEW |