Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef JINGLE_GLUE_PSEUDOTCP_ADAPTER_H_ | 5 #ifndef JINGLE_GLUE_PSEUDOTCP_ADAPTER_H_ |
| 6 #define JINGLE_GLUE_PSEUDOTCP_ADAPTER_H_ | 6 #define JINGLE_GLUE_PSEUDOTCP_ADAPTER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/timer.h" | 12 #include "base/timer.h" |
| 13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "net/base/net_log.h" | 14 #include "net/base/net_log.h" |
| 15 #include "net/socket/stream_socket.h" | 15 #include "net/socket/stream_socket.h" |
| 16 #include "third_party/libjingle/source/talk/p2p/base/pseudotcp.h" | 16 #include "third_party/libjingle/source/talk/p2p/base/pseudotcp.h" |
| 17 | 17 |
| 18 namespace jingle_glue { | 18 namespace jingle_glue { |
| 19 | 19 |
| 20 class PseudoTcpAdapter : public net::StreamSocket, | 20 class PseudoTcpAdapter : public net::StreamSocket, base::NonThreadSafe { |
|
Sergey Ulanov
2011/05/20 22:01:40
Please add some comments explaining lifetime of th
Wez
2011/05/21 08:10:55
Done.
| |
| 21 public cricket::IPseudoTcpNotify, | |
| 22 public base::NonThreadSafe { | |
| 23 public: | 21 public: |
| 24 // Creates adapter for the specified |socket|. |socket| is assumed | 22 // Creates adapter for the specified |socket|. |socket| is assumed |
| 25 // to be already connected. Takes ownership of |socket|. | 23 // to be already connected. Takes ownership of |socket|. |
| 26 PseudoTcpAdapter(net::Socket* socket); | 24 PseudoTcpAdapter(net::Socket* socket); |
| 27 virtual ~PseudoTcpAdapter(); | 25 virtual ~PseudoTcpAdapter(); |
| 28 | 26 |
| 29 // net::Socket implementation. | 27 // net::Socket implementation. |
| 30 virtual int Read(net::IOBuffer* buffer, int buffer_size, | 28 virtual int Read(net::IOBuffer* buffer, int buffer_size, |
| 31 net::CompletionCallback* callback) OVERRIDE; | 29 net::CompletionCallback* callback) OVERRIDE; |
| 32 virtual int Write(net::IOBuffer* buffer, int buffer_size, | 30 virtual int Write(net::IOBuffer* buffer, int buffer_size, |
| 33 net::CompletionCallback* callback) OVERRIDE; | 31 net::CompletionCallback* callback) OVERRIDE; |
| 34 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; | 32 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; |
| 35 virtual bool SetSendBufferSize(int32 size) OVERRIDE; | 33 virtual bool SetSendBufferSize(int32 size) OVERRIDE; |
| 36 | 34 |
| 37 // net::StreamSocket implementation. | 35 // net::StreamSocket implementation. |
| 38 virtual int Connect(net::CompletionCallback* callback) OVERRIDE; | 36 virtual int Connect(net::CompletionCallback* callback) OVERRIDE; |
| 39 virtual void Disconnect() OVERRIDE; | 37 virtual void Disconnect() OVERRIDE; |
| 40 virtual bool IsConnected() const OVERRIDE; | 38 virtual bool IsConnected() const OVERRIDE; |
| 41 virtual bool IsConnectedAndIdle() const OVERRIDE; | 39 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 42 virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE; | 40 virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE; |
| 43 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE; | 41 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE; |
| 44 virtual const net::BoundNetLog& NetLog() const OVERRIDE; | 42 virtual const net::BoundNetLog& NetLog() const OVERRIDE; |
| 45 virtual void SetSubresourceSpeculation() OVERRIDE; | 43 virtual void SetSubresourceSpeculation() OVERRIDE; |
| 46 virtual void SetOmniboxSpeculation() OVERRIDE; | 44 virtual void SetOmniboxSpeculation() OVERRIDE; |
| 47 virtual bool WasEverUsed() const OVERRIDE; | 45 virtual bool WasEverUsed() const OVERRIDE; |
| 48 virtual bool UsingTCPFastOpen() const OVERRIDE; | 46 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 49 | 47 |
| 50 // cricket::IPseudoTcpNotify implementation. | 48 private: |
| 51 virtual void OnTcpOpen(cricket::PseudoTcp* tcp) OVERRIDE; | 49 class Core; |
| 52 virtual void OnTcpReadable(cricket::PseudoTcp* tcp) OVERRIDE; | |
| 53 virtual void OnTcpWriteable(cricket::PseudoTcp* tcp) OVERRIDE; | |
| 54 virtual void OnTcpClosed(cricket::PseudoTcp* tcp, uint32 error) OVERRIDE; | |
| 55 virtual WriteResult TcpWritePacket(cricket::PseudoTcp* tcp, | |
| 56 const char* buffer, size_t len) OVERRIDE; | |
| 57 | 50 |
| 58 private: | 51 scoped_refptr<Core> core_; |
| 59 void DoReadFromSocket(); | |
| 60 void HandleReadResults(int result); | |
| 61 | |
| 62 // Callback functions for Read() and Write() in |socket_| | |
| 63 void OnRead(int result); | |
| 64 void OnWritten(int result); | |
| 65 | |
| 66 void AdjustClock(); | |
| 67 void HandleTcpClock(); | |
| 68 | |
| 69 scoped_ptr<net::Socket> socket_; | |
| 70 cricket::PseudoTcp pseudotcp_; | |
| 71 | |
| 72 net::CompletionCallback* connect_callback_; | |
| 73 scoped_refptr<net::IOBuffer> read_buffer_; | |
| 74 int read_buffer_size_; | |
| 75 net::CompletionCallback* read_callback_; | |
| 76 scoped_refptr<net::IOBuffer> write_buffer_; | |
| 77 int write_buffer_size_; | |
| 78 net::CompletionCallback* write_callback_; | |
| 79 | |
| 80 bool socket_write_pending_; | |
| 81 scoped_refptr<net::IOBuffer> socket_read_buffer_; | |
| 82 | |
| 83 net::CompletionCallbackImpl<PseudoTcpAdapter> socket_read_callback_; | |
| 84 net::CompletionCallbackImpl<PseudoTcpAdapter> socket_write_callback_; | |
| 85 | |
| 86 base::OneShotTimer<PseudoTcpAdapter> timer_; | |
| 87 | 52 |
| 88 net::BoundNetLog net_log_; | 53 net::BoundNetLog net_log_; |
| 89 | 54 |
| 90 DISALLOW_COPY_AND_ASSIGN(PseudoTcpAdapter); | 55 DISALLOW_COPY_AND_ASSIGN(PseudoTcpAdapter); |
| 91 }; | 56 }; |
| 92 | 57 |
| 93 } // namespace jingle_glue | 58 } // namespace jingle_glue |
| 94 | 59 |
| 95 #endif // JINGLE_GLUE_STREAM_SOCKET_ADAPTER_H_ | 60 #endif // JINGLE_GLUE_STREAM_SOCKET_ADAPTER_H_ |
| OLD | NEW |