1 // 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.
5 #ifndef NET_QUIC_TOOLS_QUIC_SIMPLE_PER_CONNECTION_PACKET_WRITER_H_
6 #define NET_QUIC_TOOLS_QUIC_SIMPLE_PER_CONNECTION_PACKET_WRITER_H_
8 #include "base/memory/weak_ptr.h"
9 #include "net/quic/quic_connection.h"
10 #include "net/quic/quic_packet_writer.h"
15 class QuicSimpleServerPacketWriter
;
17 // A connection-specific packet writer that notifies its connection when its
18 // writes to the shared QuicServerPacketWriter complete.
19 // This class is necessary because multiple connections can share the same
20 // QuicServerPacketWriter, so it has no way to know which connection to notify.
21 class QuicSimplePerConnectionPacketWriter
: public QuicPacketWriter
{
23 // Does not take ownership of |shared_writer| or |connection|.
24 QuicSimplePerConnectionPacketWriter(
25 QuicSimpleServerPacketWriter
* shared_writer
,
26 QuicConnection
* connection
);
27 ~QuicSimplePerConnectionPacketWriter() override
;
29 QuicPacketWriter
* shared_writer() const;
30 QuicConnection
* connection() const { return connection_
; }
32 // Default implementation of the QuicPacketWriter interface: Passes everything
33 // to |shared_writer_|.
34 WriteResult
WritePacket(const char* buffer
,
36 const IPAddressNumber
& self_address
,
37 const IPEndPoint
& peer_address
) override
;
38 bool IsWriteBlockedDataBuffered() const override
;
39 bool IsWriteBlocked() const override
;
40 void SetWritable() override
;
43 void OnWriteComplete(WriteResult result
);
45 QuicSimpleServerPacketWriter
* shared_writer_
; // Not owned.
46 QuicConnection
* connection_
; // Not owned.
48 base::WeakPtrFactory
<QuicSimplePerConnectionPacketWriter
> weak_factory_
;
50 DISALLOW_COPY_AND_ASSIGN(QuicSimplePerConnectionPacketWriter
);
56 #endif // NET_QUIC_TOOLS_QUIC_SIMPLE_PER_CONNECTION_PACKET_WRITER_H_