Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / net / tools / quic / quic_simple_server_packet_writer.h
blob182d4712d231f64acc88f40cc0c99cf46b36109b
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"
16 namespace net {
18 class QuicBlockedWriterInterface;
19 class UDPServerSocket;
20 struct WriteResult;
22 namespace tools {
24 // Chrome specific packet writer which uses a UDPServerSocket for writing
25 // data.
26 class QuicSimpleServerPacketWriter : public QuicPacketWriter {
27 public:
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(
38 const char* buffer,
39 size_t buf_len,
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;
51 protected:
52 // Do not call WritePacket on its own -- use WritePacketWithCallback
53 WriteResult WritePacket(const char* buffer,
54 size_t buf_len,
55 const IPAddressNumber& self_address,
56 const IPEndPoint& peer_address) override;
58 private:
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.
68 bool write_blocked_;
70 base::WeakPtrFactory<QuicSimpleServerPacketWriter> weak_factory_;
72 DISALLOW_COPY_AND_ASSIGN(QuicSimpleServerPacketWriter);
75 } // namespace tools
76 } // namespace net
78 #endif // NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_PACKET_WRITER_H_