OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 const char* buffer, size_t len) { | 140 const char* buffer, size_t len) { |
141 // Randomly drop the desired percentage of packets. | 141 // Randomly drop the desired percentage of packets. |
142 // Also drop packets that are larger than the configured MTU. | 142 // Also drop packets that are larger than the configured MTU. |
143 if (rtc::CreateRandomId() % 100 < static_cast<uint32_t>(loss_)) { | 143 if (rtc::CreateRandomId() % 100 < static_cast<uint32_t>(loss_)) { |
144 LOG(LS_VERBOSE) << "Randomly dropping packet, size=" << len; | 144 LOG(LS_VERBOSE) << "Randomly dropping packet, size=" << len; |
145 } else if (len > static_cast<size_t>(std::min(local_mtu_, remote_mtu_))) { | 145 } else if (len > static_cast<size_t>(std::min(local_mtu_, remote_mtu_))) { |
146 LOG(LS_VERBOSE) << "Dropping packet that exceeds path MTU, size=" << len; | 146 LOG(LS_VERBOSE) << "Dropping packet that exceeds path MTU, size=" << len; |
147 } else { | 147 } else { |
148 int id = (tcp == &local_) ? MSG_RPACKET : MSG_LPACKET; | 148 int id = (tcp == &local_) ? MSG_RPACKET : MSG_LPACKET; |
149 std::string packet(buffer, len); | 149 std::string packet(buffer, len); |
150 rtc::Thread::Current()->PostDelayed(delay_, this, id, | 150 rtc::Thread::Current()->PostDelayed(RTC_FROM_HERE, delay_, this, id, |
151 rtc::WrapMessageData(packet)); | 151 rtc::WrapMessageData(packet)); |
152 } | 152 } |
153 return WR_SUCCESS; | 153 return WR_SUCCESS; |
154 } | 154 } |
155 | 155 |
156 void UpdateLocalClock() { UpdateClock(&local_, MSG_LCLOCK); } | 156 void UpdateLocalClock() { UpdateClock(&local_, MSG_LCLOCK); } |
157 void UpdateRemoteClock() { UpdateClock(&remote_, MSG_RCLOCK); } | 157 void UpdateRemoteClock() { UpdateClock(&remote_, MSG_RCLOCK); } |
158 void UpdateClock(PseudoTcp* tcp, uint32_t message) { | 158 void UpdateClock(PseudoTcp* tcp, uint32_t message) { |
159 long interval = 0; // NOLINT | 159 long interval = 0; // NOLINT |
160 tcp->GetNextClock(PseudoTcp::Now(), interval); | 160 tcp->GetNextClock(PseudoTcp::Now(), interval); |
161 interval = std::max<int>(interval, 0L); // sometimes interval is < 0 | 161 interval = std::max<int>(interval, 0L); // sometimes interval is < 0 |
162 rtc::Thread::Current()->Clear(this, message); | 162 rtc::Thread::Current()->Clear(this, message); |
163 rtc::Thread::Current()->PostDelayed(interval, this, message); | 163 rtc::Thread::Current()->PostDelayed(RTC_FROM_HERE, interval, this, message); |
164 } | 164 } |
165 | 165 |
166 virtual void OnMessage(rtc::Message* message) { | 166 virtual void OnMessage(rtc::Message* message) { |
167 switch (message->message_id) { | 167 switch (message->message_id) { |
168 case MSG_LPACKET: { | 168 case MSG_LPACKET: { |
169 const std::string& s( | 169 const std::string& s( |
170 rtc::UseMessageData<std::string>(message->pdata)); | 170 rtc::UseMessageData<std::string>(message->pdata)); |
171 local_.NotifyPacket(s.c_str(), s.size()); | 171 local_.NotifyPacket(s.c_str(), s.size()); |
172 UpdateLocalClock(); | 172 UpdateLocalClock(); |
173 break; | 173 break; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 } | 450 } |
451 send_stream_.Rewind(); | 451 send_stream_.Rewind(); |
452 | 452 |
453 // Prepare the receive stream. | 453 // Prepare the receive stream. |
454 recv_stream_.ReserveSize(size); | 454 recv_stream_.ReserveSize(size); |
455 | 455 |
456 // Connect and wait until connected. | 456 // Connect and wait until connected. |
457 EXPECT_EQ(0, Connect()); | 457 EXPECT_EQ(0, Connect()); |
458 EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs); | 458 EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs); |
459 | 459 |
460 rtc::Thread::Current()->Post(this, MSG_WRITE); | 460 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_WRITE); |
461 EXPECT_TRUE_WAIT(have_disconnected_, kTransferTimeoutMs); | 461 EXPECT_TRUE_WAIT(have_disconnected_, kTransferTimeoutMs); |
462 | 462 |
463 ASSERT_EQ(2u, send_position_.size()); | 463 ASSERT_EQ(2u, send_position_.size()); |
464 ASSERT_EQ(2u, recv_position_.size()); | 464 ASSERT_EQ(2u, recv_position_.size()); |
465 | 465 |
466 const size_t estimated_recv_window = EstimateReceiveWindowSize(); | 466 const size_t estimated_recv_window = EstimateReceiveWindowSize(); |
467 | 467 |
468 // The difference in consecutive send positions should equal the | 468 // The difference in consecutive send positions should equal the |
469 // receive window size or match very closely. This verifies that receive | 469 // receive window size or match very closely. This verifies that receive |
470 // window is open after receiver drained all the data. | 470 // window is open after receiver drained all the data. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 556 |
557 int message_queue_size = | 557 int message_queue_size = |
558 static_cast<int>(rtc::Thread::Current()->size()); | 558 static_cast<int>(rtc::Thread::Current()->size()); |
559 // The message queue will always have at least 2 messages, an RCLOCK and | 559 // The message queue will always have at least 2 messages, an RCLOCK and |
560 // an LCLOCK, since they are added back on the delay queue at the same time | 560 // an LCLOCK, since they are added back on the delay queue at the same time |
561 // they are pulled off and therefore are never really removed. | 561 // they are pulled off and therefore are never really removed. |
562 if (message_queue_size > 2) { | 562 if (message_queue_size > 2) { |
563 // If there are non-clock messages remaining, attempt to continue sending | 563 // If there are non-clock messages remaining, attempt to continue sending |
564 // after giving those messages time to process, which should free up the | 564 // after giving those messages time to process, which should free up the |
565 // send buffer. | 565 // send buffer. |
566 rtc::Thread::Current()->PostDelayed(10, this, MSG_WRITE); | 566 rtc::Thread::Current()->PostDelayed(RTC_FROM_HERE, 10, this, MSG_WRITE); |
567 } else { | 567 } else { |
568 if (!remote_.isReceiveBufferFull()) { | 568 if (!remote_.isReceiveBufferFull()) { |
569 LOG(LS_ERROR) << "This shouldn't happen - the send buffer is full, " | 569 LOG(LS_ERROR) << "This shouldn't happen - the send buffer is full, " |
570 << "the receive buffer is not, and there are no " | 570 << "the receive buffer is not, and there are no " |
571 << "remaining messages to process."; | 571 << "remaining messages to process."; |
572 } | 572 } |
573 send_stream_.GetPosition(&position); | 573 send_stream_.GetPosition(&position); |
574 send_position_.push_back(position); | 574 send_position_.push_back(position); |
575 | 575 |
576 // Drain the receiver buffer. | 576 // Drain the receiver buffer. |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 /* Test sending data with mismatched MTUs. We should detect this and reduce | 832 /* Test sending data with mismatched MTUs. We should detect this and reduce |
833 // our packet size accordingly. | 833 // our packet size accordingly. |
834 // TODO: This doesn't actually work right now. The current code | 834 // TODO: This doesn't actually work right now. The current code |
835 // doesn't detect if the MTU is set too high on either side. | 835 // doesn't detect if the MTU is set too high on either side. |
836 TEST_F(PseudoTcpTest, TestSendWithMismatchedMtus) { | 836 TEST_F(PseudoTcpTest, TestSendWithMismatchedMtus) { |
837 SetLocalMtu(1500); | 837 SetLocalMtu(1500); |
838 SetRemoteMtu(1280); | 838 SetRemoteMtu(1280); |
839 TestTransfer(1000000); | 839 TestTransfer(1000000); |
840 } | 840 } |
841 */ | 841 */ |
OLD | NEW |