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 "jingle/glue/pseudotcp_adapter.h" | 5 #include "jingle/glue/pseudotcp_adapter.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
11 #include "net/base/completion_callback.h" | 11 #include "net/base/completion_callback.h" |
12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
15 | 15 |
16 using cricket::PseudoTcp; | 16 using cricket::PseudoTcp; |
17 | 17 |
18 namespace { | 18 namespace { |
19 const int kReadBufferSize = 65536; // Maximum size of a packet. | 19 const int kReadBufferSize = 65536; // Maximum size of a packet. |
20 const uint16 kDefaultMtu = 1280; | 20 const uint16 kDefaultMtu = 1280; |
21 } // namespace | 21 } // namespace |
22 | 22 |
23 namespace jingle_glue { | 23 namespace jingle_glue { |
24 | 24 |
25 class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify, | 25 class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify, |
26 public base::RefCounted<Core> { | 26 public base::RefCounted<Core> { |
27 public: | 27 public: |
28 Core(net::Socket* socket); | 28 Core(net::Socket* socket); |
29 virtual ~Core(); | |
30 | 29 |
31 // Functions used to implement net::StreamSocket. | 30 // Functions used to implement net::StreamSocket. |
32 int Read(net::IOBuffer* buffer, int buffer_size, | 31 int Read(net::IOBuffer* buffer, int buffer_size, |
33 const net::CompletionCallback& callback); | 32 const net::CompletionCallback& callback); |
34 int Write(net::IOBuffer* buffer, int buffer_size, | 33 int Write(net::IOBuffer* buffer, int buffer_size, |
35 const net::CompletionCallback& callback); | 34 const net::CompletionCallback& callback); |
36 int Connect(const net::CompletionCallback& callback); | 35 int Connect(const net::CompletionCallback& callback); |
37 void Disconnect(); | 36 void Disconnect(); |
38 bool IsConnected() const; | 37 bool IsConnected() const; |
39 | 38 |
(...skipping 10 matching lines...) Expand all Loading... |
50 | 49 |
51 void SetAckDelay(int delay_ms); | 50 void SetAckDelay(int delay_ms); |
52 void SetNoDelay(bool no_delay); | 51 void SetNoDelay(bool no_delay); |
53 void SetReceiveBufferSize(int32 size); | 52 void SetReceiveBufferSize(int32 size); |
54 void SetSendBufferSize(int32 size); | 53 void SetSendBufferSize(int32 size); |
55 void SetWriteWaitsForSend(bool write_waits_for_send); | 54 void SetWriteWaitsForSend(bool write_waits_for_send); |
56 | 55 |
57 void DeleteSocket(); | 56 void DeleteSocket(); |
58 | 57 |
59 private: | 58 private: |
| 59 friend class base::RefCounted<Core>; |
| 60 virtual ~Core(); |
| 61 |
60 // These are invoked by the underlying Socket, and may trigger callbacks. | 62 // These are invoked by the underlying Socket, and may trigger callbacks. |
61 // They hold a reference to |this| while running, to protect from deletion. | 63 // They hold a reference to |this| while running, to protect from deletion. |
62 void OnRead(int result); | 64 void OnRead(int result); |
63 void OnWritten(int result); | 65 void OnWritten(int result); |
64 | 66 |
65 // These may trigger callbacks, so the holder must hold a reference on | 67 // These may trigger callbacks, so the holder must hold a reference on |
66 // the stack while calling them. | 68 // the stack while calling them. |
67 void DoReadFromSocket(); | 69 void DoReadFromSocket(); |
68 void HandleReadResults(int result); | 70 void HandleReadResults(int result); |
69 void HandleTcpClock(); | 71 void HandleTcpClock(); |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 DCHECK(CalledOnValidThread()); | 587 DCHECK(CalledOnValidThread()); |
586 core_->SetNoDelay(no_delay); | 588 core_->SetNoDelay(no_delay); |
587 } | 589 } |
588 | 590 |
589 void PseudoTcpAdapter::SetWriteWaitsForSend(bool write_waits_for_send) { | 591 void PseudoTcpAdapter::SetWriteWaitsForSend(bool write_waits_for_send) { |
590 DCHECK(CalledOnValidThread()); | 592 DCHECK(CalledOnValidThread()); |
591 core_->SetWriteWaitsForSend(write_waits_for_send); | 593 core_->SetWriteWaitsForSend(write_waits_for_send); |
592 } | 594 } |
593 | 595 |
594 } // namespace jingle_glue | 596 } // namespace jingle_glue |
OLD | NEW |