blob: e93bfcfafa745c7594e5bee8ffda784827fef3b2 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright 2014 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_CORE_QUIC_PACKET_WRITER_WRAPPER_H_
6#define QUICHE_QUIC_CORE_QUIC_PACKET_WRITER_WRAPPER_H_
7
8#include <cstddef>
9#include <memory>
10
QUICHE teama6ef0a62019-03-07 20:34:33 -050011#include "net/third_party/quiche/src/quic/core/quic_packet_writer.h"
12
13namespace quic {
14
15// Wraps a writer object to allow dynamically extending functionality. Use
16// cases: replace writer while dispatcher and connections hold on to the
17// wrapper; mix in monitoring; mix in mocks in unit tests.
18class QuicPacketWriterWrapper : public QuicPacketWriter {
19 public:
20 QuicPacketWriterWrapper();
21 QuicPacketWriterWrapper(const QuicPacketWriterWrapper&) = delete;
22 QuicPacketWriterWrapper& operator=(const QuicPacketWriterWrapper&) = delete;
23 ~QuicPacketWriterWrapper() override;
24
25 // Default implementation of the QuicPacketWriter interface. Passes everything
26 // to |writer_|.
27 WriteResult WritePacket(const char* buffer,
28 size_t buf_len,
29 const QuicIpAddress& self_address,
30 const QuicSocketAddress& peer_address,
31 PerPacketOptions* options) override;
32 bool IsWriteBlocked() const override;
33 void SetWritable() override;
34 QuicByteCount GetMaxPacketSize(
35 const QuicSocketAddress& peer_address) const override;
36 bool SupportsReleaseTime() const override;
37 bool IsBatchMode() const override;
38 char* GetNextWriteLocation(const QuicIpAddress& self_address,
39 const QuicSocketAddress& peer_address) override;
40 WriteResult Flush() override;
41
42 // Takes ownership of |writer|.
43 void set_writer(QuicPacketWriter* writer);
44
45 // Does not take ownership of |writer|.
46 void set_non_owning_writer(QuicPacketWriter* writer);
47
48 virtual void set_peer_address(const QuicSocketAddress& peer_address) {}
49
50 QuicPacketWriter* writer() { return writer_; }
51
52 private:
53 void unset_writer();
54
55 QuicPacketWriter* writer_ = nullptr;
56 bool owns_writer_ = false;
57};
58
59} // namespace quic
60
61#endif // QUICHE_QUIC_CORE_QUIC_PACKET_WRITER_WRAPPER_H_