| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/protocol/pseudotcp_adapter.h" | 5 #include "remoting/protocol/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/time.h" | 9 #include "base/time/time.h" |
| 10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
| 11 #include "net/base/address_list.h" | 11 #include "net/base/address_list.h" |
| 12 #include "net/base/completion_callback.h" | 12 #include "net/base/completion_callback.h" |
| 13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 16 #include "remoting/protocol/p2p_datagram_socket.h" |
| 16 | 17 |
| 17 using cricket::PseudoTcp; | 18 using cricket::PseudoTcp; |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 const int kReadBufferSize = 65536; // Maximum size of a packet. | 21 const int kReadBufferSize = 65536; // Maximum size of a packet. |
| 21 const uint16 kDefaultMtu = 1280; | 22 const uint16 kDefaultMtu = 1280; |
| 22 } // namespace | 23 } // namespace |
| 23 | 24 |
| 24 namespace remoting { | 25 namespace remoting { |
| 25 namespace protocol { | 26 namespace protocol { |
| 26 | 27 |
| 27 class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify, | 28 class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify, |
| 28 public base::RefCounted<Core> { | 29 public base::RefCounted<Core> { |
| 29 public: | 30 public: |
| 30 explicit Core(scoped_ptr<net::Socket> socket); | 31 explicit Core(scoped_ptr<P2PDatagramSocket> socket); |
| 31 | 32 |
| 32 // Functions used to implement net::StreamSocket. | 33 // Functions used to implement net::StreamSocket. |
| 33 int Read(net::IOBuffer* buffer, int buffer_size, | 34 int Read(const scoped_refptr<net::IOBuffer>& buffer, int buffer_size, |
| 34 const net::CompletionCallback& callback); | 35 const net::CompletionCallback& callback); |
| 35 int Write(net::IOBuffer* buffer, int buffer_size, | 36 int Write(const scoped_refptr<net::IOBuffer>& buffer, int buffer_size, |
| 36 const net::CompletionCallback& callback); | 37 const net::CompletionCallback& callback); |
| 37 int Connect(const net::CompletionCallback& callback); | 38 int Connect(const net::CompletionCallback& callback); |
| 38 void Disconnect(); | |
| 39 bool IsConnected() const; | |
| 40 | 39 |
| 41 // cricket::IPseudoTcpNotify interface. | 40 // cricket::IPseudoTcpNotify interface. |
| 42 // These notifications are triggered from NotifyPacket. | 41 // These notifications are triggered from NotifyPacket. |
| 43 void OnTcpOpen(cricket::PseudoTcp* tcp) override; | 42 void OnTcpOpen(cricket::PseudoTcp* tcp) override; |
| 44 void OnTcpReadable(cricket::PseudoTcp* tcp) override; | 43 void OnTcpReadable(cricket::PseudoTcp* tcp) override; |
| 45 void OnTcpWriteable(cricket::PseudoTcp* tcp) override; | 44 void OnTcpWriteable(cricket::PseudoTcp* tcp) override; |
| 46 // This is triggered by NotifyClock or NotifyPacket. | 45 // This is triggered by NotifyClock or NotifyPacket. |
| 47 void OnTcpClosed(cricket::PseudoTcp* tcp, uint32 error) override; | 46 void OnTcpClosed(cricket::PseudoTcp* tcp, uint32 error) override; |
| 48 // This is triggered by NotifyClock, NotifyPacket, Recv and Send. | 47 // This is triggered by NotifyClock, NotifyPacket, Recv and Send. |
| 49 WriteResult TcpWritePacket(cricket::PseudoTcp* tcp, | 48 WriteResult TcpWritePacket(cricket::PseudoTcp* tcp, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 78 void CheckWriteComplete(); | 77 void CheckWriteComplete(); |
| 79 | 78 |
| 80 // This re-sets |timer| without triggering callbacks. | 79 // This re-sets |timer| without triggering callbacks. |
| 81 void AdjustClock(); | 80 void AdjustClock(); |
| 82 | 81 |
| 83 net::CompletionCallback connect_callback_; | 82 net::CompletionCallback connect_callback_; |
| 84 net::CompletionCallback read_callback_; | 83 net::CompletionCallback read_callback_; |
| 85 net::CompletionCallback write_callback_; | 84 net::CompletionCallback write_callback_; |
| 86 | 85 |
| 87 cricket::PseudoTcp pseudo_tcp_; | 86 cricket::PseudoTcp pseudo_tcp_; |
| 88 scoped_ptr<net::Socket> socket_; | 87 scoped_ptr<P2PDatagramSocket> socket_; |
| 89 | 88 |
| 90 scoped_refptr<net::IOBuffer> read_buffer_; | 89 scoped_refptr<net::IOBuffer> read_buffer_; |
| 91 int read_buffer_size_; | 90 int read_buffer_size_; |
| 92 scoped_refptr<net::IOBuffer> write_buffer_; | 91 scoped_refptr<net::IOBuffer> write_buffer_; |
| 93 int write_buffer_size_; | 92 int write_buffer_size_; |
| 94 | 93 |
| 95 // Whether we need to wait for data to be sent before completing write. | 94 // Whether we need to wait for data to be sent before completing write. |
| 96 bool write_waits_for_send_; | 95 bool write_waits_for_send_; |
| 97 | 96 |
| 98 // Set to true in the write-waits-for-send mode when we've | 97 // Set to true in the write-waits-for-send mode when we've |
| 99 // successfully writtend data to the send buffer and waiting for the | 98 // successfully writtend data to the send buffer and waiting for the |
| 100 // data to be sent to the remote end. | 99 // data to be sent to the remote end. |
| 101 bool waiting_write_position_; | 100 bool waiting_write_position_; |
| 102 | 101 |
| 103 // Number of the bytes written by the last write stored while we wait | 102 // Number of the bytes written by the last write stored while we wait |
| 104 // for the data to be sent (i.e. when waiting_write_position_ = true). | 103 // for the data to be sent (i.e. when waiting_write_position_ = true). |
| 105 int last_write_result_; | 104 int last_write_result_; |
| 106 | 105 |
| 107 bool socket_write_pending_; | 106 bool socket_write_pending_; |
| 108 scoped_refptr<net::IOBuffer> socket_read_buffer_; | 107 scoped_refptr<net::IOBuffer> socket_read_buffer_; |
| 109 | 108 |
| 110 base::OneShotTimer<Core> timer_; | 109 base::OneShotTimer<Core> timer_; |
| 111 | 110 |
| 112 DISALLOW_COPY_AND_ASSIGN(Core); | 111 DISALLOW_COPY_AND_ASSIGN(Core); |
| 113 }; | 112 }; |
| 114 | 113 |
| 115 | 114 |
| 116 PseudoTcpAdapter::Core::Core(scoped_ptr<net::Socket> socket) | 115 PseudoTcpAdapter::Core::Core(scoped_ptr<P2PDatagramSocket> socket) |
| 117 : pseudo_tcp_(this, 0), | 116 : pseudo_tcp_(this, 0), |
| 118 socket_(socket.Pass()), | 117 socket_(socket.Pass()), |
| 119 write_waits_for_send_(false), | 118 write_waits_for_send_(false), |
| 120 waiting_write_position_(false), | 119 waiting_write_position_(false), |
| 121 socket_write_pending_(false) { | 120 socket_write_pending_(false) { |
| 122 // Doesn't trigger callbacks. | 121 // Doesn't trigger callbacks. |
| 123 pseudo_tcp_.NotifyMTU(kDefaultMtu); | 122 pseudo_tcp_.NotifyMTU(kDefaultMtu); |
| 124 } | 123 } |
| 125 | 124 |
| 126 PseudoTcpAdapter::Core::~Core() { | 125 PseudoTcpAdapter::Core::~Core() { |
| 127 } | 126 } |
| 128 | 127 |
| 129 int PseudoTcpAdapter::Core::Read(net::IOBuffer* buffer, int buffer_size, | 128 int PseudoTcpAdapter::Core::Read(const scoped_refptr<net::IOBuffer>& buffer, |
| 129 int buffer_size, |
| 130 const net::CompletionCallback& callback) { | 130 const net::CompletionCallback& callback) { |
| 131 DCHECK(read_callback_.is_null()); | 131 DCHECK(read_callback_.is_null()); |
| 132 | 132 |
| 133 // Reference the Core in case a callback deletes the adapter. | 133 // Reference the Core in case a callback deletes the adapter. |
| 134 scoped_refptr<Core> core(this); | 134 scoped_refptr<Core> core(this); |
| 135 | 135 |
| 136 int result = pseudo_tcp_.Recv(buffer->data(), buffer_size); | 136 int result = pseudo_tcp_.Recv(buffer->data(), buffer_size); |
| 137 if (result < 0) { | 137 if (result < 0) { |
| 138 result = net::MapSystemError(pseudo_tcp_.GetError()); | 138 result = net::MapSystemError(pseudo_tcp_.GetError()); |
| 139 DCHECK(result < 0); | 139 DCHECK(result < 0); |
| 140 } | 140 } |
| 141 | 141 |
| 142 if (result == net::ERR_IO_PENDING) { | 142 if (result == net::ERR_IO_PENDING) { |
| 143 read_buffer_ = buffer; | 143 read_buffer_ = buffer; |
| 144 read_buffer_size_ = buffer_size; | 144 read_buffer_size_ = buffer_size; |
| 145 read_callback_ = callback; | 145 read_callback_ = callback; |
| 146 } | 146 } |
| 147 | 147 |
| 148 AdjustClock(); | 148 AdjustClock(); |
| 149 | 149 |
| 150 return result; | 150 return result; |
| 151 } | 151 } |
| 152 | 152 |
| 153 int PseudoTcpAdapter::Core::Write(net::IOBuffer* buffer, int buffer_size, | 153 int PseudoTcpAdapter::Core::Write(const scoped_refptr<net::IOBuffer>& buffer, |
| 154 int buffer_size, |
| 154 const net::CompletionCallback& callback) { | 155 const net::CompletionCallback& callback) { |
| 155 DCHECK(write_callback_.is_null()); | 156 DCHECK(write_callback_.is_null()); |
| 156 | 157 |
| 157 // Reference the Core in case a callback deletes the adapter. | 158 // Reference the Core in case a callback deletes the adapter. |
| 158 scoped_refptr<Core> core(this); | 159 scoped_refptr<Core> core(this); |
| 159 | 160 |
| 160 int result = pseudo_tcp_.Send(buffer->data(), buffer_size); | 161 int result = pseudo_tcp_.Send(buffer->data(), buffer_size); |
| 161 if (result < 0) { | 162 if (result < 0) { |
| 162 result = net::MapSystemError(pseudo_tcp_.GetError()); | 163 result = net::MapSystemError(pseudo_tcp_.GetError()); |
| 163 DCHECK(result < 0); | 164 DCHECK(result < 0); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 return net::ERR_FAILED; | 203 return net::ERR_FAILED; |
| 203 | 204 |
| 204 AdjustClock(); | 205 AdjustClock(); |
| 205 | 206 |
| 206 connect_callback_ = callback; | 207 connect_callback_ = callback; |
| 207 DoReadFromSocket(); | 208 DoReadFromSocket(); |
| 208 | 209 |
| 209 return net::ERR_IO_PENDING; | 210 return net::ERR_IO_PENDING; |
| 210 } | 211 } |
| 211 | 212 |
| 212 void PseudoTcpAdapter::Core::Disconnect() { | |
| 213 // Don't dispatch outstanding callbacks, as mandated by net::StreamSocket. | |
| 214 read_callback_.Reset(); | |
| 215 read_buffer_ = NULL; | |
| 216 write_callback_.Reset(); | |
| 217 write_buffer_ = NULL; | |
| 218 connect_callback_.Reset(); | |
| 219 | |
| 220 // TODO(wez): Connect should succeed if called after Disconnect, which | |
| 221 // PseudoTcp doesn't support, so we need to teardown the internal PseudoTcp | |
| 222 // and create a new one in Connect. | |
| 223 // TODO(wez): Close sets a shutdown flag inside PseudoTcp but has no other | |
| 224 // effect. This should be addressed in PseudoTcp, really. | |
| 225 // In the meantime we can fake OnTcpClosed notification and tear down the | |
| 226 // PseudoTcp. | |
| 227 pseudo_tcp_.Close(true); | |
| 228 } | |
| 229 | |
| 230 bool PseudoTcpAdapter::Core::IsConnected() const { | |
| 231 return pseudo_tcp_.State() == PseudoTcp::TCP_ESTABLISHED; | |
| 232 } | |
| 233 | |
| 234 void PseudoTcpAdapter::Core::OnTcpOpen(PseudoTcp* tcp) { | 213 void PseudoTcpAdapter::Core::OnTcpOpen(PseudoTcp* tcp) { |
| 235 DCHECK(tcp == &pseudo_tcp_); | 214 DCHECK(tcp == &pseudo_tcp_); |
| 236 | 215 |
| 237 if (!connect_callback_.is_null()) { | 216 if (!connect_callback_.is_null()) { |
| 238 net::CompletionCallback callback = connect_callback_; | 217 net::CompletionCallback callback = connect_callback_; |
| 239 connect_callback_.Reset(); | 218 connect_callback_.Reset(); |
| 240 callback.Run(net::OK); | 219 callback.Run(net::OK); |
| 241 } | 220 } |
| 242 | 221 |
| 243 OnTcpReadable(tcp); | 222 OnTcpReadable(tcp); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 313 |
| 335 void PseudoTcpAdapter::Core::SetSendBufferSize(int32 size) { | 314 void PseudoTcpAdapter::Core::SetSendBufferSize(int32 size) { |
| 336 pseudo_tcp_.SetOption(cricket::PseudoTcp::OPT_SNDBUF, size); | 315 pseudo_tcp_.SetOption(cricket::PseudoTcp::OPT_SNDBUF, size); |
| 337 } | 316 } |
| 338 | 317 |
| 339 void PseudoTcpAdapter::Core::SetWriteWaitsForSend(bool write_waits_for_send) { | 318 void PseudoTcpAdapter::Core::SetWriteWaitsForSend(bool write_waits_for_send) { |
| 340 write_waits_for_send_ = write_waits_for_send; | 319 write_waits_for_send_ = write_waits_for_send; |
| 341 } | 320 } |
| 342 | 321 |
| 343 void PseudoTcpAdapter::Core::DeleteSocket() { | 322 void PseudoTcpAdapter::Core::DeleteSocket() { |
| 323 // Don't dispatch outstanding callbacks when the socket is deleted. |
| 324 read_callback_.Reset(); |
| 325 read_buffer_ = NULL; |
| 326 write_callback_.Reset(); |
| 327 write_buffer_ = NULL; |
| 328 connect_callback_.Reset(); |
| 329 |
| 344 socket_.reset(); | 330 socket_.reset(); |
| 345 } | 331 } |
| 346 | 332 |
| 347 cricket::IPseudoTcpNotify::WriteResult PseudoTcpAdapter::Core::TcpWritePacket( | 333 cricket::IPseudoTcpNotify::WriteResult PseudoTcpAdapter::Core::TcpWritePacket( |
| 348 PseudoTcp* tcp, | 334 PseudoTcp* tcp, |
| 349 const char* buffer, | 335 const char* buffer, |
| 350 size_t len) { | 336 size_t len) { |
| 351 DCHECK_EQ(tcp, &pseudo_tcp_); | 337 DCHECK_EQ(tcp, &pseudo_tcp_); |
| 352 | 338 |
| 353 // If we already have a write pending, we behave like a congested network, | 339 // If we already have a write pending, we behave like a congested network, |
| 354 // returning success for the write, but dropping the packet. PseudoTcp will | 340 // returning success for the write, but dropping the packet. PseudoTcp will |
| 355 // back-off and retransmit, adjusting for the perceived congestion. | 341 // back-off and retransmit, adjusting for the perceived congestion. |
| 356 if (socket_write_pending_) | 342 if (socket_write_pending_) |
| 357 return IPseudoTcpNotify::WR_SUCCESS; | 343 return IPseudoTcpNotify::WR_SUCCESS; |
| 358 | 344 |
| 359 scoped_refptr<net::IOBuffer> write_buffer = new net::IOBuffer(len); | 345 scoped_refptr<net::IOBuffer> write_buffer = new net::IOBuffer(len); |
| 360 memcpy(write_buffer->data(), buffer, len); | 346 memcpy(write_buffer->data(), buffer, len); |
| 361 | 347 |
| 362 // Our underlying socket is datagram-oriented, which means it should either | 348 // Our underlying socket is datagram-oriented, which means it should either |
| 363 // send exactly as many bytes as we requested, or fail. | 349 // send exactly as many bytes as we requested, or fail. |
| 364 int result; | 350 int result; |
| 365 if (socket_.get()) { | 351 if (socket_) { |
| 366 result = socket_->Write( | 352 result = socket_->Send( |
| 367 write_buffer.get(), len, | 353 write_buffer.get(), len, |
| 368 base::Bind(&PseudoTcpAdapter::Core::OnWritten, base::Unretained(this))); | 354 base::Bind(&PseudoTcpAdapter::Core::OnWritten, base::Unretained(this))); |
| 369 } else { | 355 } else { |
| 370 result = net::ERR_CONNECTION_CLOSED; | 356 result = net::ERR_CONNECTION_CLOSED; |
| 371 } | 357 } |
| 372 if (result == net::ERR_IO_PENDING) { | 358 if (result == net::ERR_IO_PENDING) { |
| 373 socket_write_pending_ = true; | 359 socket_write_pending_ = true; |
| 374 return IPseudoTcpNotify::WR_SUCCESS; | 360 return IPseudoTcpNotify::WR_SUCCESS; |
| 375 } else if (result == net::ERR_MSG_TOO_BIG) { | 361 } else if (result == net::ERR_MSG_TOO_BIG) { |
| 376 return IPseudoTcpNotify::WR_TOO_LARGE; | 362 return IPseudoTcpNotify::WR_TOO_LARGE; |
| 377 } else if (result < 0) { | 363 } else if (result < 0) { |
| 378 return IPseudoTcpNotify::WR_FAIL; | 364 return IPseudoTcpNotify::WR_FAIL; |
| 379 } else { | 365 } else { |
| 380 return IPseudoTcpNotify::WR_SUCCESS; | 366 return IPseudoTcpNotify::WR_SUCCESS; |
| 381 } | 367 } |
| 382 } | 368 } |
| 383 | 369 |
| 384 void PseudoTcpAdapter::Core::DoReadFromSocket() { | 370 void PseudoTcpAdapter::Core::DoReadFromSocket() { |
| 385 if (!socket_read_buffer_.get()) | 371 if (!socket_read_buffer_.get()) |
| 386 socket_read_buffer_ = new net::IOBuffer(kReadBufferSize); | 372 socket_read_buffer_ = new net::IOBuffer(kReadBufferSize); |
| 387 | 373 |
| 388 int result = 1; | 374 int result = 1; |
| 389 while (socket_.get() && result > 0) { | 375 while (socket_ && result > 0) { |
| 390 result = socket_->Read( | 376 result = socket_->Recv( |
| 391 socket_read_buffer_.get(), | 377 socket_read_buffer_.get(), kReadBufferSize, |
| 392 kReadBufferSize, | |
| 393 base::Bind(&PseudoTcpAdapter::Core::OnRead, base::Unretained(this))); | 378 base::Bind(&PseudoTcpAdapter::Core::OnRead, base::Unretained(this))); |
| 394 if (result != net::ERR_IO_PENDING) | 379 if (result != net::ERR_IO_PENDING) |
| 395 HandleReadResults(result); | 380 HandleReadResults(result); |
| 396 } | 381 } |
| 397 } | 382 } |
| 398 | 383 |
| 399 void PseudoTcpAdapter::Core::HandleReadResults(int result) { | 384 void PseudoTcpAdapter::Core::HandleReadResults(int result) { |
| 400 if (result <= 0) { | 385 if (result <= 0) { |
| 401 LOG(ERROR) << "Read returned " << result; | 386 LOG(ERROR) << "Read returned " << result; |
| 402 return; | 387 return; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 waiting_write_position_ = false; | 439 waiting_write_position_ = false; |
| 455 | 440 |
| 456 net::CompletionCallback callback = write_callback_; | 441 net::CompletionCallback callback = write_callback_; |
| 457 write_callback_.Reset(); | 442 write_callback_.Reset(); |
| 458 write_buffer_ = NULL; | 443 write_buffer_ = NULL; |
| 459 callback.Run(last_write_result_); | 444 callback.Run(last_write_result_); |
| 460 } | 445 } |
| 461 } | 446 } |
| 462 } | 447 } |
| 463 | 448 |
| 464 // Public interface implemention. | 449 // Public interface implementation. |
| 465 | 450 |
| 466 PseudoTcpAdapter::PseudoTcpAdapter(scoped_ptr<net::Socket> socket) | 451 PseudoTcpAdapter::PseudoTcpAdapter(scoped_ptr<P2PDatagramSocket> socket) |
| 467 : core_(new Core(socket.Pass())) { | 452 : core_(new Core(socket.Pass())) { |
| 468 } | 453 } |
| 469 | 454 |
| 470 PseudoTcpAdapter::~PseudoTcpAdapter() { | 455 PseudoTcpAdapter::~PseudoTcpAdapter() { |
| 471 Disconnect(); | |
| 472 | |
| 473 // Make sure that the underlying socket is destroyed before PseudoTcp. | 456 // Make sure that the underlying socket is destroyed before PseudoTcp. |
| 474 core_->DeleteSocket(); | 457 core_->DeleteSocket(); |
| 475 } | 458 } |
| 476 | 459 |
| 477 int PseudoTcpAdapter::Read(net::IOBuffer* buffer, int buffer_size, | 460 int PseudoTcpAdapter::Read(const scoped_refptr<net::IOBuffer>& buffer, |
| 461 int buffer_size, |
| 478 const net::CompletionCallback& callback) { | 462 const net::CompletionCallback& callback) { |
| 479 DCHECK(CalledOnValidThread()); | 463 DCHECK(CalledOnValidThread()); |
| 480 return core_->Read(buffer, buffer_size, callback); | 464 return core_->Read(buffer, buffer_size, callback); |
| 481 } | 465 } |
| 482 | 466 |
| 483 int PseudoTcpAdapter::Write(net::IOBuffer* buffer, int buffer_size, | 467 int PseudoTcpAdapter::Write(const scoped_refptr<net::IOBuffer>& buffer, |
| 468 int buffer_size, |
| 484 const net::CompletionCallback& callback) { | 469 const net::CompletionCallback& callback) { |
| 485 DCHECK(CalledOnValidThread()); | 470 DCHECK(CalledOnValidThread()); |
| 486 return core_->Write(buffer, buffer_size, callback); | 471 return core_->Write(buffer, buffer_size, callback); |
| 487 } | 472 } |
| 488 | 473 |
| 489 int PseudoTcpAdapter::SetReceiveBufferSize(int32 size) { | 474 int PseudoTcpAdapter::SetReceiveBufferSize(int32 size) { |
| 490 DCHECK(CalledOnValidThread()); | 475 DCHECK(CalledOnValidThread()); |
| 491 | |
| 492 core_->SetReceiveBufferSize(size); | 476 core_->SetReceiveBufferSize(size); |
| 493 return net::OK; | 477 return net::OK; |
| 494 } | 478 } |
| 495 | 479 |
| 496 int PseudoTcpAdapter::SetSendBufferSize(int32 size) { | 480 int PseudoTcpAdapter::SetSendBufferSize(int32 size) { |
| 497 DCHECK(CalledOnValidThread()); | 481 DCHECK(CalledOnValidThread()); |
| 498 | |
| 499 core_->SetSendBufferSize(size); | 482 core_->SetSendBufferSize(size); |
| 500 return net::OK; | 483 return net::OK; |
| 501 } | 484 } |
| 502 | 485 |
| 503 int PseudoTcpAdapter::Connect(const net::CompletionCallback& callback) { | 486 int PseudoTcpAdapter::Connect(const net::CompletionCallback& callback) { |
| 504 DCHECK(CalledOnValidThread()); | 487 DCHECK(CalledOnValidThread()); |
| 505 | |
| 506 // net::StreamSocket requires that Connect return OK if already connected. | |
| 507 if (IsConnected()) | |
| 508 return net::OK; | |
| 509 | |
| 510 return core_->Connect(callback); | 488 return core_->Connect(callback); |
| 511 } | 489 } |
| 512 | 490 |
| 513 void PseudoTcpAdapter::Disconnect() { | |
| 514 DCHECK(CalledOnValidThread()); | |
| 515 core_->Disconnect(); | |
| 516 } | |
| 517 | |
| 518 bool PseudoTcpAdapter::IsConnected() const { | |
| 519 return core_->IsConnected(); | |
| 520 } | |
| 521 | |
| 522 bool PseudoTcpAdapter::IsConnectedAndIdle() const { | |
| 523 DCHECK(CalledOnValidThread()); | |
| 524 NOTIMPLEMENTED(); | |
| 525 return false; | |
| 526 } | |
| 527 | |
| 528 int PseudoTcpAdapter::GetPeerAddress(net::IPEndPoint* address) const { | |
| 529 DCHECK(CalledOnValidThread()); | |
| 530 | |
| 531 // We don't have a meaningful peer address, but we can't return an | |
| 532 // error, so we return a INADDR_ANY instead. | |
| 533 net::IPAddressNumber ip_address(net::kIPv4AddressSize); | |
| 534 *address = net::IPEndPoint(ip_address, 0); | |
| 535 return net::OK; | |
| 536 } | |
| 537 | |
| 538 int PseudoTcpAdapter::GetLocalAddress(net::IPEndPoint* address) const { | |
| 539 DCHECK(CalledOnValidThread()); | |
| 540 NOTIMPLEMENTED(); | |
| 541 return net::ERR_FAILED; | |
| 542 } | |
| 543 | |
| 544 const net::BoundNetLog& PseudoTcpAdapter::NetLog() const { | |
| 545 DCHECK(CalledOnValidThread()); | |
| 546 return net_log_; | |
| 547 } | |
| 548 | |
| 549 void PseudoTcpAdapter::SetSubresourceSpeculation() { | |
| 550 DCHECK(CalledOnValidThread()); | |
| 551 NOTIMPLEMENTED(); | |
| 552 } | |
| 553 | |
| 554 void PseudoTcpAdapter::SetOmniboxSpeculation() { | |
| 555 DCHECK(CalledOnValidThread()); | |
| 556 NOTIMPLEMENTED(); | |
| 557 } | |
| 558 | |
| 559 bool PseudoTcpAdapter::WasEverUsed() const { | |
| 560 DCHECK(CalledOnValidThread()); | |
| 561 NOTIMPLEMENTED(); | |
| 562 return true; | |
| 563 } | |
| 564 | |
| 565 bool PseudoTcpAdapter::UsingTCPFastOpen() const { | |
| 566 DCHECK(CalledOnValidThread()); | |
| 567 return false; | |
| 568 } | |
| 569 | |
| 570 bool PseudoTcpAdapter::WasNpnNegotiated() const { | |
| 571 DCHECK(CalledOnValidThread()); | |
| 572 return false; | |
| 573 } | |
| 574 | |
| 575 net::NextProto PseudoTcpAdapter::GetNegotiatedProtocol() const { | |
| 576 DCHECK(CalledOnValidThread()); | |
| 577 return net::kProtoUnknown; | |
| 578 } | |
| 579 | |
| 580 bool PseudoTcpAdapter::GetSSLInfo(net::SSLInfo* ssl_info) { | |
| 581 DCHECK(CalledOnValidThread()); | |
| 582 return false; | |
| 583 } | |
| 584 | |
| 585 void PseudoTcpAdapter::GetConnectionAttempts( | |
| 586 net::ConnectionAttempts* out) const { | |
| 587 DCHECK(CalledOnValidThread()); | |
| 588 out->clear(); | |
| 589 } | |
| 590 | |
| 591 void PseudoTcpAdapter::SetAckDelay(int delay_ms) { | 491 void PseudoTcpAdapter::SetAckDelay(int delay_ms) { |
| 592 DCHECK(CalledOnValidThread()); | 492 DCHECK(CalledOnValidThread()); |
| 593 core_->SetAckDelay(delay_ms); | 493 core_->SetAckDelay(delay_ms); |
| 594 } | 494 } |
| 595 | 495 |
| 596 void PseudoTcpAdapter::SetNoDelay(bool no_delay) { | 496 void PseudoTcpAdapter::SetNoDelay(bool no_delay) { |
| 597 DCHECK(CalledOnValidThread()); | 497 DCHECK(CalledOnValidThread()); |
| 598 core_->SetNoDelay(no_delay); | 498 core_->SetNoDelay(no_delay); |
| 599 } | 499 } |
| 600 | 500 |
| 601 void PseudoTcpAdapter::SetWriteWaitsForSend(bool write_waits_for_send) { | 501 void PseudoTcpAdapter::SetWriteWaitsForSend(bool write_waits_for_send) { |
| 602 DCHECK(CalledOnValidThread()); | 502 DCHECK(CalledOnValidThread()); |
| 603 core_->SetWriteWaitsForSend(write_waits_for_send); | 503 core_->SetWriteWaitsForSend(write_waits_for_send); |
| 604 } | 504 } |
| 605 | 505 |
| 606 } // namespace protocol | 506 } // namespace protocol |
| 607 } // namespace remoting | 507 } // namespace remoting |
| OLD | NEW |