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_SERVER_PACKET_WRITER_H_
6 #define NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_PACKET_WRITER_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/weak_ptr.h"
11 #include "net/base/ip_endpoint.h"
12 #include "net/quic/quic_connection.h"
13 #include "net/quic/quic_packet_writer.h"
14 #include "net/quic/quic_protocol.h"
18 class QuicBlockedWriterInterface
;
19 class UDPServerSocket
;
24 // Chrome specific packet writer which uses a UDPServerSocket for writing
26 class QuicSimpleServerPacketWriter
: public QuicPacketWriter
{
28 typedef base::Callback
<void(WriteResult
)> WriteCallback
;
30 QuicSimpleServerPacketWriter(UDPServerSocket
* socket
,
31 QuicBlockedWriterInterface
* blocked_writer
);
32 ~QuicSimpleServerPacketWriter() override
;
34 // Use this method to write packets rather than WritePacket:
35 // QuicSimpleServerPacketWriter requires a callback to exist for every
36 // write, which will be called once the write completes.
37 virtual WriteResult
WritePacketWithCallback(
40 const IPAddressNumber
& self_address
,
41 const IPEndPoint
& peer_address
,
42 WriteCallback callback
);
44 void OnWriteComplete(int rv
);
46 // QuicPacketWriter implementation:
47 bool IsWriteBlockedDataBuffered() const override
;
48 bool IsWriteBlocked() const override
;
49 void SetWritable() override
;
52 // Do not call WritePacket on its own -- use WritePacketWithCallback
53 WriteResult
WritePacket(const char* buffer
,
55 const IPAddressNumber
& self_address
,
56 const IPEndPoint
& peer_address
) override
;
59 UDPServerSocket
* socket_
;
61 // To be notified after every successful asynchronous write.
62 QuicBlockedWriterInterface
* blocked_writer_
;
64 // To call once the write completes.
65 WriteCallback callback_
;
67 // Whether a write is currently in flight.
70 base::WeakPtrFactory
<QuicSimpleServerPacketWriter
> weak_factory_
;
72 DISALLOW_COPY_AND_ASSIGN(QuicSimpleServerPacketWriter
);
78 #endif // NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_PACKET_WRITER_H_