| 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 #include "jingle/glue/pseudotcp_adapter.h" | 5 #include "jingle/glue/pseudotcp_adapter.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
| 10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // cricket::IPseudoTcpNotify interface. | 39 // cricket::IPseudoTcpNotify interface. |
| 40 // These notifications are triggered from NotifyPacket. | 40 // These notifications are triggered from NotifyPacket. |
| 41 virtual void OnTcpOpen(cricket::PseudoTcp* tcp) OVERRIDE; | 41 virtual void OnTcpOpen(cricket::PseudoTcp* tcp) OVERRIDE; |
| 42 virtual void OnTcpReadable(cricket::PseudoTcp* tcp) OVERRIDE; | 42 virtual void OnTcpReadable(cricket::PseudoTcp* tcp) OVERRIDE; |
| 43 virtual void OnTcpWriteable(cricket::PseudoTcp* tcp) OVERRIDE; | 43 virtual void OnTcpWriteable(cricket::PseudoTcp* tcp) OVERRIDE; |
| 44 // This is triggered by NotifyClock or NotifyPacket. | 44 // This is triggered by NotifyClock or NotifyPacket. |
| 45 virtual void OnTcpClosed(cricket::PseudoTcp* tcp, uint32 error) OVERRIDE; | 45 virtual void OnTcpClosed(cricket::PseudoTcp* tcp, uint32 error) OVERRIDE; |
| 46 // This is triggered by NotifyClock, NotifyPacket, Recv and Send. | 46 // This is triggered by NotifyClock, NotifyPacket, Recv and Send. |
| 47 virtual WriteResult TcpWritePacket(cricket::PseudoTcp* tcp, | 47 virtual WriteResult TcpWritePacket(cricket::PseudoTcp* tcp, |
| 48 const char* buffer, size_t len) OVERRIDE; | 48 const char* buffer, size_t len) OVERRIDE; |
| 49 |
| 50 void SetAckDelay(int delay_ms); |
| 51 void SetNagling(bool nagling); |
| 52 |
| 49 private: | 53 private: |
| 50 // These are invoked by the underlying Socket, and may trigger callbacks. | 54 // These are invoked by the underlying Socket, and may trigger callbacks. |
| 51 // They hold a reference to |this| while running, to protect from deletion. | 55 // They hold a reference to |this| while running, to protect from deletion. |
| 52 void OnRead(int result); | 56 void OnRead(int result); |
| 53 void OnWritten(int result); | 57 void OnWritten(int result); |
| 54 | 58 |
| 55 // These may trigger callbacks, so the holder must hold a reference on | 59 // These may trigger callbacks, so the holder must hold a reference on |
| 56 // the stack while calling them. | 60 // the stack while calling them. |
| 57 void DoReadFromSocket(); | 61 void DoReadFromSocket(); |
| 58 void HandleReadResults(int result); | 62 void HandleReadResults(int result); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 callback->Run(net::MapSystemError(error)); | 266 callback->Run(net::MapSystemError(error)); |
| 263 } | 267 } |
| 264 | 268 |
| 265 if (write_callback_) { | 269 if (write_callback_) { |
| 266 net::CompletionCallback* callback = write_callback_; | 270 net::CompletionCallback* callback = write_callback_; |
| 267 write_callback_ = NULL; | 271 write_callback_ = NULL; |
| 268 callback->Run(net::MapSystemError(error)); | 272 callback->Run(net::MapSystemError(error)); |
| 269 } | 273 } |
| 270 } | 274 } |
| 271 | 275 |
| 276 void PseudoTcpAdapter::Core::SetAckDelay(int delay_ms) { |
| 277 pseudo_tcp_.SetOption(cricket::PseudoTcp::OPT_ACKDELAY, delay_ms); |
| 278 } |
| 279 |
| 280 void PseudoTcpAdapter::Core::SetNagling(bool nagling) { |
| 281 pseudo_tcp_.SetOption(cricket::PseudoTcp::OPT_NODELAY, nagling ? 1 : 0); |
| 282 } |
| 283 |
| 272 cricket::IPseudoTcpNotify::WriteResult PseudoTcpAdapter::Core::TcpWritePacket( | 284 cricket::IPseudoTcpNotify::WriteResult PseudoTcpAdapter::Core::TcpWritePacket( |
| 273 PseudoTcp* tcp, | 285 PseudoTcp* tcp, |
| 274 const char* buffer, | 286 const char* buffer, |
| 275 size_t len) { | 287 size_t len) { |
| 276 DCHECK_EQ(tcp, &pseudo_tcp_); | 288 DCHECK_EQ(tcp, &pseudo_tcp_); |
| 277 | 289 |
| 278 // If we already have a write pending, we behave like a congested network, | 290 // If we already have a write pending, we behave like a congested network, |
| 279 // returning success for the write, but dropping the packet. PseudoTcp will | 291 // returning success for the write, but dropping the packet. PseudoTcp will |
| 280 // back-off and retransmit, adjusting for the perceived congestion. | 292 // back-off and retransmit, adjusting for the perceived congestion. |
| 281 if (socket_write_pending_) | 293 if (socket_write_pending_) |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 int64 PseudoTcpAdapter::NumBytesRead() const { | 478 int64 PseudoTcpAdapter::NumBytesRead() const { |
| 467 DCHECK(CalledOnValidThread()); | 479 DCHECK(CalledOnValidThread()); |
| 468 return -1; | 480 return -1; |
| 469 } | 481 } |
| 470 | 482 |
| 471 base::TimeDelta PseudoTcpAdapter::GetConnectTimeMicros() const { | 483 base::TimeDelta PseudoTcpAdapter::GetConnectTimeMicros() const { |
| 472 DCHECK(CalledOnValidThread()); | 484 DCHECK(CalledOnValidThread()); |
| 473 return base::TimeDelta::FromMicroseconds(-1); | 485 return base::TimeDelta::FromMicroseconds(-1); |
| 474 } | 486 } |
| 475 | 487 |
| 488 void PseudoTcpAdapter::SetAckDelay(int delay_ms) { |
| 489 DCHECK(CalledOnValidThread()); |
| 490 core_->SetAckDelay(delay_ms); |
| 491 } |
| 492 |
| 493 void PseudoTcpAdapter::SetNagling(bool nagling) { |
| 494 DCHECK(CalledOnValidThread()); |
| 495 core_->SetNagling(nagling); |
| 496 } |
| 497 |
| 476 } // namespace jingle_glue | 498 } // namespace jingle_glue |
| OLD | NEW |