OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_DEFAULT_PACKET_WRITER_H_ |
6 #define NET_QUIC_QUIC_DEFAULT_PACKET_WRITER_H_ | 6 #define NET_QUIC_QUIC_DEFAULT_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/udp/datagram_client_socket.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 | 17 |
18 struct WriteResult; | 18 struct WriteResult; |
19 | 19 |
20 // Chrome specific packet writer which uses a DatagramClientSocket for writing | 20 // Chrome specific packet writer which uses a DatagramClientSocket for writing |
21 // data. | 21 // data. |
22 class NET_EXPORT_PRIVATE QuicDefaultPacketWriter : public QuicPacketWriter { | 22 class NET_EXPORT_PRIVATE QuicDefaultPacketWriter : public QuicPacketWriter { |
23 public: | 23 public: |
24 QuicDefaultPacketWriter(); | 24 QuicDefaultPacketWriter(); |
25 explicit QuicDefaultPacketWriter(DatagramClientSocket* socket); | 25 explicit QuicDefaultPacketWriter(DatagramClientSocket* socket); |
26 virtual ~QuicDefaultPacketWriter(); | 26 virtual ~QuicDefaultPacketWriter(); |
27 | 27 |
28 // QuicPacketWriter | 28 // QuicPacketWriter |
29 virtual WriteResult WritePacket( | 29 virtual WriteResult WritePacket( |
30 const char* buffer, size_t buf_len, | 30 const char* buffer, |
31 const net::IPAddressNumber& self_address, | 31 size_t buf_len, |
32 const net::IPEndPoint& peer_address) OVERRIDE; | 32 const IPAddressNumber& self_address, |
| 33 const IPEndPoint& peer_address, |
| 34 base::Callback<void(WriteResult wr)> callback) OVERRIDE; |
33 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE; | 35 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE; |
34 virtual bool IsWriteBlocked() const OVERRIDE; | 36 virtual bool IsWriteBlocked() const OVERRIDE; |
35 virtual void SetWritable() OVERRIDE; | 37 virtual void SetWritable() OVERRIDE; |
36 | 38 |
37 void OnWriteComplete(int rv); | 39 void OnWriteComplete(int rv); |
38 void SetConnection(QuicConnection* connection) { | 40 |
39 connection_ = connection; | 41 // Set the writer to notify when writes complete. |
| 42 void SetWriterToUnblock(QuicBlockedWriterInterface* blocked_writer) { |
| 43 blocked_writer_ = blocked_writer; |
40 } | 44 } |
41 | 45 |
42 protected: | 46 protected: |
43 void set_write_blocked(bool is_blocked) { | 47 void set_write_blocked(bool is_blocked) { |
44 write_blocked_ = is_blocked; | 48 write_blocked_ = is_blocked; |
45 } | 49 } |
46 | 50 |
47 private: | 51 private: |
48 base::WeakPtrFactory<QuicDefaultPacketWriter> weak_factory_; | 52 base::WeakPtrFactory<QuicDefaultPacketWriter> weak_factory_; |
49 DatagramClientSocket* socket_; | 53 DatagramClientSocket* socket_; |
50 QuicConnection* connection_; | 54 |
| 55 // To be notified after every successful write. |
| 56 QuicBlockedWriterInterface* blocked_writer_; |
| 57 |
| 58 // To be called after every successful write. May be null. |
| 59 base::Callback<void(WriteResult wr)> callback_; |
| 60 |
| 61 // Whether a write is currently in flight. |
51 bool write_blocked_; | 62 bool write_blocked_; |
52 | 63 |
53 DISALLOW_COPY_AND_ASSIGN(QuicDefaultPacketWriter); | 64 DISALLOW_COPY_AND_ASSIGN(QuicDefaultPacketWriter); |
54 }; | 65 }; |
55 | 66 |
56 } // namespace net | 67 } // namespace net |
57 | 68 |
58 #endif // NET_QUIC_QUIC_DEFAULT_PACKET_WRITER_H_ | 69 #endif // NET_QUIC_QUIC_DEFAULT_PACKET_WRITER_H_ |
OLD | NEW |