OLD | NEW |
1 // Copyright 2013 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_DEFAULT_PACKET_WRITER_H_ | 5 #ifndef NET_QUIC_QUIC_PER_CONNECTION_PACKET_WRITER_H_ |
6 #define NET_QUIC_QUIC_DEFAULT_PACKET_WRITER_H_ | 6 #define NET_QUIC_QUIC_PER_CONNECTION_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/datagram_client_socket.h" | 14 #include "net/quic/quic_types.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 | 17 |
18 struct WriteResult; | 18 class QuicServerPacketWriter; |
19 | 19 |
20 // Chrome specific packet writer which uses a DatagramClientSocket for writing | 20 // A connection-specific packet writer that notifies its connection when its |
21 // data. | 21 // writes to the shared QuicServerPacketWriter complete. |
22 class NET_EXPORT_PRIVATE QuicDefaultPacketWriter : public QuicPacketWriter { | 22 // This class is necessary because multiple connections can share the same |
| 23 // QuicServerPacketWriter, so it has no way to know which connection to notify. |
| 24 // TODO(dmz) Try to merge with Chrome's default packet writer |
| 25 class QuicPerConnectionPacketWriter : public QuicPacketWriter { |
23 public: | 26 public: |
24 QuicDefaultPacketWriter(); | 27 QuicPerConnectionPacketWriter(QuicServerPacketWriter* writer); |
25 explicit QuicDefaultPacketWriter(DatagramClientSocket* socket); | 28 virtual ~QuicPerConnectionPacketWriter(); |
26 virtual ~QuicDefaultPacketWriter(); | 29 |
| 30 // Set the connection to notify after writes complete. |
| 31 void set_connection(QuicConnection* connection) { connection_ = connection; } |
27 | 32 |
28 // QuicPacketWriter | 33 // QuicPacketWriter |
29 virtual WriteResult WritePacket(const char* buffer, | 34 virtual WriteResult WritePacket(const char* buffer, |
30 size_t buf_len, | 35 size_t buf_len, |
31 const IPAddressNumber& self_address, | 36 const IPAddressNumber& self_address, |
32 const IPEndPoint& peer_address) OVERRIDE; | 37 const IPEndPoint& peer_address) OVERRIDE; |
33 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE; | 38 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE; |
34 virtual bool IsWriteBlocked() const OVERRIDE; | 39 virtual bool IsWriteBlocked() const OVERRIDE; |
35 virtual void SetWritable() OVERRIDE; | 40 virtual void SetWritable() OVERRIDE; |
36 | 41 |
37 void OnWriteComplete(int rv); | 42 private: |
38 void SetConnection(QuicConnection* connection) { | 43 void OnWriteComplete(WriteResult result); |
39 connection_ = connection; | |
40 } | |
41 | 44 |
42 protected: | 45 base::WeakPtrFactory<QuicPerConnectionPacketWriter> weak_factory_; |
43 void set_write_blocked(bool is_blocked) { | 46 QuicServerPacketWriter* writer_; // Not owned. |
44 write_blocked_ = is_blocked; | 47 QuicConnection* connection_; |
45 } | |
46 | 48 |
47 private: | 49 DISALLOW_COPY_AND_ASSIGN(QuicPerConnectionPacketWriter); |
48 base::WeakPtrFactory<QuicDefaultPacketWriter> weak_factory_; | |
49 DatagramClientSocket* socket_; | |
50 QuicConnection* connection_; | |
51 bool write_blocked_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(QuicDefaultPacketWriter); | |
54 }; | 50 }; |
55 | 51 |
56 } // namespace net | 52 } // namespace net |
57 | 53 |
58 #endif // NET_QUIC_QUIC_DEFAULT_PACKET_WRITER_H_ | 54 #endif // NET_QUIC_QUIC_PER_CONNECTION_PACKET_WRITER_H_ |
OLD | NEW |