OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 return WriteResult(WRITE_STATUS_BLOCKED, -1); | 306 return WriteResult(WRITE_STATUS_BLOCKED, -1); |
307 } | 307 } |
308 last_packet_size_ = packet.length(); | 308 last_packet_size_ = packet.length(); |
309 return WriteResult(WRITE_STATUS_OK, last_packet_size_); | 309 return WriteResult(WRITE_STATUS_OK, last_packet_size_); |
310 } | 310 } |
311 | 311 |
312 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { | 312 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { |
313 return is_write_blocked_data_buffered_; | 313 return is_write_blocked_data_buffered_; |
314 } | 314 } |
315 | 315 |
| 316 // Resets the visitor's state by clearing out the headers and frames. |
| 317 void Reset() { |
| 318 visitor_.Reset(); |
| 319 } |
| 320 |
316 QuicPacketHeader* header() { return visitor_.header(); } | 321 QuicPacketHeader* header() { return visitor_.header(); } |
317 | 322 |
318 size_t frame_count() const { return visitor_.frame_count(); } | 323 size_t frame_count() const { return visitor_.frame_count(); } |
319 | 324 |
320 QuicAckFrame* ack() { return visitor_.ack(); } | 325 QuicAckFrame* ack() { return visitor_.ack(); } |
321 | 326 |
322 QuicCongestionFeedbackFrame* feedback() { return visitor_.feedback(); } | 327 QuicCongestionFeedbackFrame* feedback() { return visitor_.feedback(); } |
323 | 328 |
324 QuicConnectionCloseFrame* close() { return visitor_.close(); } | 329 QuicConnectionCloseFrame* close() { return visitor_.close(); } |
325 | 330 |
(...skipping 2277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2603 TEST_F(QuicConnectionTest, SendDelayedAckOnSecondPacket) { | 2608 TEST_F(QuicConnectionTest, SendDelayedAckOnSecondPacket) { |
2604 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2609 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2605 ProcessPacket(1); | 2610 ProcessPacket(1); |
2606 ProcessPacket(2); | 2611 ProcessPacket(2); |
2607 // Check that ack is sent and that delayed ack alarm is reset. | 2612 // Check that ack is sent and that delayed ack alarm is reset. |
2608 EXPECT_EQ(1u, writer_->frame_count()); | 2613 EXPECT_EQ(1u, writer_->frame_count()); |
2609 EXPECT_TRUE(writer_->ack()); | 2614 EXPECT_TRUE(writer_->ack()); |
2610 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2615 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
2611 } | 2616 } |
2612 | 2617 |
| 2618 TEST_F(QuicConnectionTest, NoAckOnOldNacks) { |
| 2619 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2620 // Drop one packet, triggering a sequence of acks. |
| 2621 ProcessPacket(2); |
| 2622 EXPECT_EQ(1u, writer_->frame_count()); |
| 2623 EXPECT_TRUE(writer_->ack()); |
| 2624 writer_->Reset(); |
| 2625 ProcessPacket(3); |
| 2626 EXPECT_EQ(1u, writer_->frame_count()); |
| 2627 EXPECT_TRUE(writer_->ack()); |
| 2628 writer_->Reset(); |
| 2629 ProcessPacket(4); |
| 2630 EXPECT_EQ(1u, writer_->frame_count()); |
| 2631 EXPECT_TRUE(writer_->ack()); |
| 2632 writer_->Reset(); |
| 2633 ProcessPacket(5); |
| 2634 EXPECT_EQ(1u, writer_->frame_count()); |
| 2635 EXPECT_TRUE(writer_->ack()); |
| 2636 // Now only set the timer on the 6th packet, instead of sending another ack. |
| 2637 writer_->Reset(); |
| 2638 ProcessPacket(6); |
| 2639 EXPECT_EQ(0u, writer_->frame_count()); |
| 2640 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 2641 } |
| 2642 |
2613 TEST_F(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) { | 2643 TEST_F(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) { |
2614 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2644 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2615 ProcessPacket(1); | 2645 ProcessPacket(1); |
2616 connection_.SendStreamDataWithString(kStreamId3, "foo", 0, !kFin, NULL); | 2646 connection_.SendStreamDataWithString(kStreamId3, "foo", 0, !kFin, NULL); |
2617 // Check that ack is bundled with outgoing data and that delayed ack | 2647 // Check that ack is bundled with outgoing data and that delayed ack |
2618 // alarm is reset. | 2648 // alarm is reset. |
2619 EXPECT_EQ(2u, writer_->frame_count()); | 2649 EXPECT_EQ(2u, writer_->frame_count()); |
2620 EXPECT_TRUE(writer_->ack()); | 2650 EXPECT_TRUE(writer_->ack()); |
2621 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2651 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
2622 } | 2652 } |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3378 true); | 3408 true); |
3379 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), | 3409 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), |
3380 false); | 3410 false); |
3381 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); | 3411 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); |
3382 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 3412 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
3383 } | 3413 } |
3384 | 3414 |
3385 } // namespace | 3415 } // namespace |
3386 } // namespace test | 3416 } // namespace test |
3387 } // namespace net | 3417 } // namespace net |
OLD | NEW |