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