summaryrefslogtreecommitdiffstats
path: root/jingle/glue/pseudotcp_adapter.h
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 01:30:51 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 01:30:51 +0000
commitdb6609b8a05c594585ef6e04cb3f0e995bc3ce7c (patch)
tree94f518ae8ec9ade935dc81f20be192b60392a160 /jingle/glue/pseudotcp_adapter.h
parent05a7794358d8de30baa93a784b7420f5f962d236 (diff)
downloadchromium_src-db6609b8a05c594585ef6e04cb3f0e995bc3ce7c.zip
chromium_src-db6609b8a05c594585ef6e04cb3f0e995bc3ce7c.tar.gz
chromium_src-db6609b8a05c594585ef6e04cb3f0e995bc3ce7c.tar.bz2
Implement PseudoTCP adapter.
The new PseudoTcpAdapter will replace PseudoTcpChannel in remoting/protocol and will also be used for Pepper P2P APIs. BUG=None TEST=Unittests Review URL: http://codereview.chromium.org/6879119 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82606 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle/glue/pseudotcp_adapter.h')
-rw-r--r--jingle/glue/pseudotcp_adapter.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/jingle/glue/pseudotcp_adapter.h b/jingle/glue/pseudotcp_adapter.h
new file mode 100644
index 0000000..0001991
--- /dev/null
+++ b/jingle/glue/pseudotcp_adapter.h
@@ -0,0 +1,95 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef JINGLE_GLUE_PSEUDOTCP_ADAPTER_H_
+#define JINGLE_GLUE_PSEUDOTCP_ADAPTER_H_
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/timer.h"
+#include "base/threading/non_thread_safe.h"
+#include "net/base/net_log.h"
+#include "net/socket/client_socket.h"
+#include "third_party/libjingle/source/talk/p2p/base/pseudotcp.h"
+
+namespace jingle_glue {
+
+class PseudoTcpAdapter : public net::ClientSocket,
+ public cricket::IPseudoTcpNotify,
+ public base::NonThreadSafe {
+ public:
+ // Creates adapter for the specified |socket|. |socket| is assumed
+ // to be already connected. Takes ownership of |socket|.
+ PseudoTcpAdapter(net::Socket* socket);
+ virtual ~PseudoTcpAdapter();
+
+ // net::Socket implementation.
+ virtual int Read(net::IOBuffer* buffer, int buffer_size,
+ net::CompletionCallback* callback) OVERRIDE;
+ virtual int Write(net::IOBuffer* buffer, int buffer_size,
+ net::CompletionCallback* callback) OVERRIDE;
+ virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
+ virtual bool SetSendBufferSize(int32 size) OVERRIDE;
+
+ // net::ClientSocket implementation.
+ virtual int Connect(net::CompletionCallback* callback) OVERRIDE;
+ virtual void Disconnect() OVERRIDE;
+ virtual bool IsConnected() const OVERRIDE;
+ virtual bool IsConnectedAndIdle() const OVERRIDE;
+ virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE;
+ virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE;
+ virtual const net::BoundNetLog& NetLog() const OVERRIDE;
+ virtual void SetSubresourceSpeculation() OVERRIDE;
+ virtual void SetOmniboxSpeculation() OVERRIDE;
+ virtual bool WasEverUsed() const OVERRIDE;
+ virtual bool UsingTCPFastOpen() const OVERRIDE;
+
+ // cricket::IPseudoTcpNotify implementation.
+ virtual void OnTcpOpen(cricket::PseudoTcp* tcp) OVERRIDE;
+ virtual void OnTcpReadable(cricket::PseudoTcp* tcp) OVERRIDE;
+ virtual void OnTcpWriteable(cricket::PseudoTcp* tcp) OVERRIDE;
+ virtual void OnTcpClosed(cricket::PseudoTcp* tcp, uint32 error) OVERRIDE;
+ virtual WriteResult TcpWritePacket(cricket::PseudoTcp* tcp,
+ const char* buffer, size_t len) OVERRIDE;
+
+ private:
+ void DoReadFromSocket();
+ void HandleReadResults(int result);
+
+ // Callback functions for Read() and Write() in |socket_|
+ void OnRead(int result);
+ void OnWritten(int result);
+
+ void AdjustClock();
+ void HandleTcpClock();
+
+ scoped_ptr<net::Socket> socket_;
+ cricket::PseudoTcp pseudotcp_;
+
+ net::CompletionCallback* connect_callback_;
+ scoped_refptr<net::IOBuffer> read_buffer_;
+ int read_buffer_size_;
+ net::CompletionCallback* read_callback_;
+ scoped_refptr<net::IOBuffer> write_buffer_;
+ int write_buffer_size_;
+ net::CompletionCallback* write_callback_;
+
+ bool socket_write_pending_;
+ scoped_refptr<net::IOBuffer> socket_read_buffer_;
+
+ net::CompletionCallbackImpl<PseudoTcpAdapter> socket_read_callback_;
+ net::CompletionCallbackImpl<PseudoTcpAdapter> socket_write_callback_;
+
+ base::OneShotTimer<PseudoTcpAdapter> timer_;
+
+ net::BoundNetLog net_log_;
+
+ DISALLOW_COPY_AND_ASSIGN(PseudoTcpAdapter);
+};
+
+} // namespace jingle_glue
+
+#endif // JINGLE_GLUE_STREAM_SOCKET_ADAPTER_H_