OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_QUIC_QUIC_SERVER_PACKET_WRITER_H_ | 5 #ifndef NET_QUIC_QUIC_SERVER_PACKET_WRITER_H_ |
6 #define NET_QUIC_QUIC_SERVER_PACKET_WRITER_H_ | 6 #define NET_QUIC_QUIC_SERVER_PACKET_WRITER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
11 #include "net/quic/quic_connection.h" | 11 #include "net/quic/quic_connection.h" |
12 #include "net/quic/quic_packet_writer.h" | 12 #include "net/quic/quic_packet_writer.h" |
13 #include "net/quic/quic_protocol.h" | 13 #include "net/quic/quic_protocol.h" |
14 #include "net/udp/udp_server_socket.h" | |
15 | 14 |
16 namespace net { | 15 namespace net { |
17 | 16 |
17 class QuicBlockedWriterInterface; | |
18 class UDPServerSocket; | |
18 struct WriteResult; | 19 struct WriteResult; |
19 | 20 |
20 // Chrome specific packet writer which uses a UDPServerSocket for writing | 21 // Chrome specific packet writer which uses a UDPServerSocket for writing |
21 // data. | 22 // data. |
22 class QuicServerPacketWriter : public QuicPacketWriter { | 23 class QuicServerPacketWriter : public QuicPacketWriter { |
23 public: | 24 public: |
24 QuicServerPacketWriter(); | 25 typedef base::Callback<void(WriteResult)> WriteCallback; |
25 explicit QuicServerPacketWriter(UDPServerSocket* socket); | 26 |
27 QuicServerPacketWriter(UDPServerSocket* socket, | |
28 QuicBlockedWriterInterface* blocked_writer); | |
26 virtual ~QuicServerPacketWriter(); | 29 virtual ~QuicServerPacketWriter(); |
27 | 30 |
31 // Use this method to write packets rather than WritePacket: this class | |
wtc
2014/06/23 23:12:16
Should "this class" be changed to "this method"?
dmziegler
2014/06/24 00:08:53
No, actually, QuicServerPacketWriter can't be used
| |
32 // requires a callback to exist, which will be called once the write | |
33 // completes. | |
34 virtual WriteResult WritePacketWithCallback( | |
35 const char* buffer, | |
36 size_t buf_len, | |
37 const IPAddressNumber& self_address, | |
38 const IPEndPoint& peer_address, | |
39 WriteCallback callback); | |
40 | |
28 // QuicPacketWriter | 41 // QuicPacketWriter |
29 virtual WriteResult WritePacket(const char* buffer, | 42 virtual WriteResult WritePacket(const char* buffer, |
30 size_t buf_len, | 43 size_t buf_len, |
31 const net::IPAddressNumber& self_address, | 44 const IPAddressNumber& self_address, |
32 const net::IPEndPoint& peer_address) OVERRIDE; | 45 const IPEndPoint& peer_address) OVERRIDE; |
33 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE; | 46 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE; |
34 virtual bool IsWriteBlocked() const OVERRIDE; | 47 virtual bool IsWriteBlocked() const OVERRIDE; |
35 virtual void SetWritable() OVERRIDE; | 48 virtual void SetWritable() OVERRIDE; |
36 | 49 |
37 void OnWriteComplete(int rv); | 50 void OnWriteComplete(int rv); |
38 void SetConnection(QuicConnection* connection) { | 51 |
39 connection_ = connection; | |
40 } | |
41 | 52 |
42 private: | 53 private: |
43 base::WeakPtrFactory<QuicServerPacketWriter> weak_factory_; | 54 base::WeakPtrFactory<QuicServerPacketWriter> weak_factory_; |
44 UDPServerSocket* socket_; | 55 UDPServerSocket* socket_; |
45 QuicConnection* connection_; | 56 |
57 // To be notified after every successful asynchronous write. | |
58 QuicBlockedWriterInterface* blocked_writer_; | |
59 | |
60 // To call once the write completes. | |
61 WriteCallback callback_; | |
62 | |
63 // Whether a write is currently in flight. | |
46 bool write_blocked_; | 64 bool write_blocked_; |
47 | 65 |
48 DISALLOW_COPY_AND_ASSIGN(QuicServerPacketWriter); | 66 DISALLOW_COPY_AND_ASSIGN(QuicServerPacketWriter); |
49 }; | 67 }; |
50 | 68 |
51 } // namespace net | 69 } // namespace net |
52 | 70 |
53 #endif // NET_QUIC_QUIC_SERVER_PACKET_WRITER_H_ | 71 #endif // NET_QUIC_QUIC_SERVER_PACKET_WRITER_H_ |
OLD | NEW |