Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Unified Diff: remoting/protocol/pseudotcp_adapter.cc

Issue 1197853003: Add P2PDatagramSocket and P2PStreamSocket interfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/pseudotcp_adapter.cc
diff --git a/remoting/protocol/pseudotcp_adapter.cc b/remoting/protocol/pseudotcp_adapter.cc
index 796db24299f8185d9958f4acb8922d851036719b..e59fb346c562941eb07cbdcb8a7115878bd71f8b 100644
--- a/remoting/protocol/pseudotcp_adapter.cc
+++ b/remoting/protocol/pseudotcp_adapter.cc
@@ -27,7 +27,7 @@ namespace protocol {
class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify,
public base::RefCounted<Core> {
public:
- explicit Core(scoped_ptr<net::Socket> socket);
+ explicit Core(scoped_ptr<P2PDatagramSocket> socket);
// Functions used to implement net::StreamSocket.
int Read(net::IOBuffer* buffer, int buffer_size,
@@ -35,8 +35,6 @@ class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify,
int Write(net::IOBuffer* buffer, int buffer_size,
const net::CompletionCallback& callback);
int Connect(const net::CompletionCallback& callback);
- void Disconnect();
- bool IsConnected() const;
// cricket::IPseudoTcpNotify interface.
// These notifications are triggered from NotifyPacket.
@@ -85,7 +83,7 @@ class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify,
net::CompletionCallback write_callback_;
cricket::PseudoTcp pseudo_tcp_;
- scoped_ptr<net::Socket> socket_;
+ scoped_ptr<P2PDatagramSocket> socket_;
scoped_refptr<net::IOBuffer> read_buffer_;
int read_buffer_size_;
@@ -113,7 +111,7 @@ class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify,
};
-PseudoTcpAdapter::Core::Core(scoped_ptr<net::Socket> socket)
+PseudoTcpAdapter::Core::Core(scoped_ptr<P2PDatagramSocket> socket)
: pseudo_tcp_(this, 0),
socket_(socket.Pass()),
write_waits_for_send_(false),
@@ -209,28 +207,6 @@ int PseudoTcpAdapter::Core::Connect(const net::CompletionCallback& callback) {
return net::ERR_IO_PENDING;
}
-void PseudoTcpAdapter::Core::Disconnect() {
- // Don't dispatch outstanding callbacks, as mandated by net::StreamSocket.
- read_callback_.Reset();
- read_buffer_ = NULL;
- write_callback_.Reset();
- write_buffer_ = NULL;
- connect_callback_.Reset();
-
- // TODO(wez): Connect should succeed if called after Disconnect, which
- // PseudoTcp doesn't support, so we need to teardown the internal PseudoTcp
- // and create a new one in Connect.
- // TODO(wez): Close sets a shutdown flag inside PseudoTcp but has no other
- // effect. This should be addressed in PseudoTcp, really.
- // In the meantime we can fake OnTcpClosed notification and tear down the
- // PseudoTcp.
- pseudo_tcp_.Close(true);
-}
-
-bool PseudoTcpAdapter::Core::IsConnected() const {
- return pseudo_tcp_.State() == PseudoTcp::TCP_ESTABLISHED;
-}
-
void PseudoTcpAdapter::Core::OnTcpOpen(PseudoTcp* tcp) {
DCHECK(tcp == &pseudo_tcp_);
@@ -341,6 +317,13 @@ void PseudoTcpAdapter::Core::SetWriteWaitsForSend(bool write_waits_for_send) {
}
void PseudoTcpAdapter::Core::DeleteSocket() {
+ // Don't dispatch outstanding callbacks when the socket is deleted.
+ read_callback_.Reset();
+ read_buffer_ = NULL;
+ write_callback_.Reset();
+ write_buffer_ = NULL;
+ connect_callback_.Reset();
+
socket_.reset();
}
@@ -362,7 +345,7 @@ cricket::IPseudoTcpNotify::WriteResult PseudoTcpAdapter::Core::TcpWritePacket(
// Our underlying socket is datagram-oriented, which means it should either
// send exactly as many bytes as we requested, or fail.
int result;
- if (socket_.get()) {
+ if (socket_) {
result = socket_->Write(
write_buffer.get(), len,
base::Bind(&PseudoTcpAdapter::Core::OnWritten, base::Unretained(this)));
@@ -386,10 +369,9 @@ void PseudoTcpAdapter::Core::DoReadFromSocket() {
socket_read_buffer_ = new net::IOBuffer(kReadBufferSize);
int result = 1;
- while (socket_.get() && result > 0) {
+ while (socket_ && result > 0) {
result = socket_->Read(
- socket_read_buffer_.get(),
- kReadBufferSize,
+ socket_read_buffer_.get(), kReadBufferSize,
base::Bind(&PseudoTcpAdapter::Core::OnRead, base::Unretained(this)));
if (result != net::ERR_IO_PENDING)
HandleReadResults(result);
@@ -461,15 +443,13 @@ void PseudoTcpAdapter::Core::CheckWriteComplete() {
}
}
-// Public interface implemention.
+// Public interface implementation.
-PseudoTcpAdapter::PseudoTcpAdapter(scoped_ptr<net::Socket> socket)
+PseudoTcpAdapter::PseudoTcpAdapter(scoped_ptr<P2PDatagramSocket> socket)
: core_(new Core(socket.Pass())) {
}
PseudoTcpAdapter::~PseudoTcpAdapter() {
- Disconnect();
-
// Make sure that the underlying socket is destroyed before PseudoTcp.
core_->DeleteSocket();
}
@@ -488,106 +468,21 @@ int PseudoTcpAdapter::Write(net::IOBuffer* buffer, int buffer_size,
int PseudoTcpAdapter::SetReceiveBufferSize(int32 size) {
DCHECK(CalledOnValidThread());
-
core_->SetReceiveBufferSize(size);
return net::OK;
}
int PseudoTcpAdapter::SetSendBufferSize(int32 size) {
DCHECK(CalledOnValidThread());
-
core_->SetSendBufferSize(size);
return net::OK;
}
int PseudoTcpAdapter::Connect(const net::CompletionCallback& callback) {
DCHECK(CalledOnValidThread());
-
- // net::StreamSocket requires that Connect return OK if already connected.
- if (IsConnected())
- return net::OK;
-
return core_->Connect(callback);
}
-void PseudoTcpAdapter::Disconnect() {
- DCHECK(CalledOnValidThread());
- core_->Disconnect();
-}
-
-bool PseudoTcpAdapter::IsConnected() const {
- return core_->IsConnected();
-}
-
-bool PseudoTcpAdapter::IsConnectedAndIdle() const {
- DCHECK(CalledOnValidThread());
- NOTIMPLEMENTED();
- return false;
-}
-
-int PseudoTcpAdapter::GetPeerAddress(net::IPEndPoint* address) const {
- DCHECK(CalledOnValidThread());
-
- // We don't have a meaningful peer address, but we can't return an
- // error, so we return a INADDR_ANY instead.
- net::IPAddressNumber ip_address(net::kIPv4AddressSize);
- *address = net::IPEndPoint(ip_address, 0);
- return net::OK;
-}
-
-int PseudoTcpAdapter::GetLocalAddress(net::IPEndPoint* address) const {
- DCHECK(CalledOnValidThread());
- NOTIMPLEMENTED();
- return net::ERR_FAILED;
-}
-
-const net::BoundNetLog& PseudoTcpAdapter::NetLog() const {
- DCHECK(CalledOnValidThread());
- return net_log_;
-}
-
-void PseudoTcpAdapter::SetSubresourceSpeculation() {
- DCHECK(CalledOnValidThread());
- NOTIMPLEMENTED();
-}
-
-void PseudoTcpAdapter::SetOmniboxSpeculation() {
- DCHECK(CalledOnValidThread());
- NOTIMPLEMENTED();
-}
-
-bool PseudoTcpAdapter::WasEverUsed() const {
- DCHECK(CalledOnValidThread());
- NOTIMPLEMENTED();
- return true;
-}
-
-bool PseudoTcpAdapter::UsingTCPFastOpen() const {
- DCHECK(CalledOnValidThread());
- return false;
-}
-
-bool PseudoTcpAdapter::WasNpnNegotiated() const {
- DCHECK(CalledOnValidThread());
- return false;
-}
-
-net::NextProto PseudoTcpAdapter::GetNegotiatedProtocol() const {
- DCHECK(CalledOnValidThread());
- return net::kProtoUnknown;
-}
-
-bool PseudoTcpAdapter::GetSSLInfo(net::SSLInfo* ssl_info) {
- DCHECK(CalledOnValidThread());
- return false;
-}
-
-void PseudoTcpAdapter::GetConnectionAttempts(
- net::ConnectionAttempts* out) const {
- DCHECK(CalledOnValidThread());
- out->clear();
-}
-
void PseudoTcpAdapter::SetAckDelay(int delay_ms) {
DCHECK(CalledOnValidThread());
core_->SetAckDelay(delay_ms);

Powered by Google App Engine
This is Rietveld 408576698