blob: e6dac045a89f9bb97164c6ccabadf3e44715b9f6 [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 team5be974e2020-12-29 18:35:24 -050011#include "quic/core/quic_packet_writer.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050012
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.
dschinazie2116422019-10-29 11:54:26 -070018class QUIC_NO_EXPORT QuicPacketWriterWrapper : public QuicPacketWriter {
QUICHE teama6ef0a62019-03-07 20:34:33 -050019 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;
wub50d4c712020-05-19 15:48:28 -070038 QuicPacketBuffer GetNextWriteLocation(
39 const QuicIpAddress& self_address,
40 const QuicSocketAddress& peer_address) override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050041 WriteResult Flush() override;
42
43 // Takes ownership of |writer|.
44 void set_writer(QuicPacketWriter* writer);
45
46 // Does not take ownership of |writer|.
47 void set_non_owning_writer(QuicPacketWriter* writer);
48
dschinazi17d42422019-06-18 16:35:07 -070049 virtual void set_peer_address(const QuicSocketAddress& /*peer_address*/) {}
QUICHE teama6ef0a62019-03-07 20:34:33 -050050
51 QuicPacketWriter* writer() { return writer_; }
52
53 private:
54 void unset_writer();
55
56 QuicPacketWriter* writer_ = nullptr;
57 bool owns_writer_ = false;
58};
59
60} // namespace quic
61
62#endif // QUICHE_QUIC_CORE_QUIC_PACKET_WRITER_WRAPPER_H_