QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright 2017 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 | #include "net/third_party/quiche/src/quic/test_tools/bad_packet_writer.h" |
| 6 | |
| 7 | namespace quic { |
| 8 | namespace test { |
| 9 | |
| 10 | BadPacketWriter::BadPacketWriter(size_t packet_causing_write_error, |
| 11 | int error_code) |
| 12 | : packet_causing_write_error_(packet_causing_write_error), |
| 13 | error_code_(error_code) {} |
| 14 | |
| 15 | BadPacketWriter::~BadPacketWriter() {} |
| 16 | |
| 17 | WriteResult BadPacketWriter::WritePacket(const char* buffer, |
| 18 | size_t buf_len, |
| 19 | const QuicIpAddress& self_address, |
| 20 | const QuicSocketAddress& peer_address, |
| 21 | PerPacketOptions* options) { |
| 22 | if (error_code_ == 0 || packet_causing_write_error_ > 0) { |
| 23 | if (packet_causing_write_error_ > 0) { |
| 24 | --packet_causing_write_error_; |
| 25 | } |
| 26 | return QuicPacketWriterWrapper::WritePacket(buffer, buf_len, self_address, |
| 27 | peer_address, options); |
| 28 | } |
| 29 | // It's time to cause write error. |
| 30 | int error_code = error_code_; |
| 31 | error_code_ = 0; |
| 32 | return WriteResult(WRITE_STATUS_ERROR, error_code); |
| 33 | } |
| 34 | |
| 35 | } // namespace test |
| 36 | } // namespace quic |