1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef QUICHE_QUIC_TEST_TOOLS_PACKET_REORDERING_WRITER_H_ 6 #define QUICHE_QUIC_TEST_TOOLS_PACKET_REORDERING_WRITER_H_ 7 8 #include "quiche/quic/core/quic_packet_writer_wrapper.h" 9 10 namespace quic { 11 12 namespace test { 13 14 // This packet writer allows delaying writing the next packet after 15 // SetDelay(num_packets_to_wait) 16 // is called and buffer this packet and write it after it writes next 17 // |num_packets_to_wait| packets. It doesn't support delaying a packet while 18 // there is already a packet delayed. 19 class PacketReorderingWriter : public QuicPacketWriterWrapper { 20 public: 21 PacketReorderingWriter(); 22 23 ~PacketReorderingWriter() override; 24 25 WriteResult WritePacket(const char* buffer, size_t buf_len, 26 const QuicIpAddress& self_address, 27 const QuicSocketAddress& peer_address, 28 PerPacketOptions* options) override; 29 30 void SetDelay(size_t num_packets_to_wait); 31 32 private: 33 bool delay_next_ = false; 34 size_t num_packets_to_wait_ = 0; 35 std::string delayed_data_; 36 QuicIpAddress delayed_self_address_; 37 QuicSocketAddress delayed_peer_address_; 38 std::unique_ptr<PerPacketOptions> delayed_options_; 39 }; 40 41 } // namespace test 42 } // namespace quic 43 44 #endif // QUICHE_QUIC_TEST_TOOLS_PACKET_REORDERING_WRITER_H_ 45