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_CHROMIUM_PACKET_WRITER_H_ | 5 #ifndef NET_QUIC_QUIC_CHROMIUM_PACKET_WRITER_H_ |
6 #define NET_QUIC_QUIC_CHROMIUM_PACKET_WRITER_H_ | 6 #define NET_QUIC_QUIC_CHROMIUM_PACKET_WRITER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
13 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
14 #include "net/quic/core/quic_connection.h" | 14 #include "net/quic/core/quic_connection.h" |
15 #include "net/quic/core/quic_packet_writer.h" | 15 #include "net/quic/core/quic_packet_writer.h" |
16 #include "net/quic/core/quic_protocol.h" | 16 #include "net/quic/core/quic_protocol.h" |
17 #include "net/quic/core/quic_types.h" | 17 #include "net/quic/core/quic_types.h" |
18 #include "net/udp/datagram_client_socket.h" | 18 #include "net/udp/datagram_client_socket.h" |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 // Chrome specific packet writer which uses a datagram Socket for writing data. | 22 // Chrome specific packet writer which uses a datagram Socket for writing data. |
23 class NET_EXPORT_PRIVATE QuicChromiumPacketWriter : public QuicPacketWriter { | 23 class NET_EXPORT_PRIVATE QuicChromiumPacketWriter : public QuicPacketWriter { |
24 public: | 24 public: |
25 // Interface which receives notifications on socket write errors. | 25 // Delegate interface which receives notifications on socket write events. |
26 class NET_EXPORT_PRIVATE WriteErrorObserver { | 26 class NET_EXPORT_PRIVATE Delegate { |
27 public: | 27 public: |
28 // Called on socket write error, with the error code of the failure | 28 // Called when a socket write attempt results in a failure, so |
29 // and the packet that was not written as a result of the failure. | 29 // that the delegate may recover from it by perhaps rewriting the |
30 // An implementation must return error code from the rewrite | 30 // packet to a different socket. An implementation must return the |
31 // attempt if there was one, else return |error_code|. | 31 // return value from the rewrite attempt if there is one, and |
32 virtual int OnWriteError(int error_code, | 32 // |error_code| otherwise. |
33 scoped_refptr<StringIOBuffer> last_packet) = 0; | 33 virtual int HandleWriteError(int error_code, |
34 scoped_refptr<StringIOBuffer> last_packet) = 0; | |
35 // Called to propagate a write error to observers above of the final error. | |
36 virtual void OnWriteError(int error_code) = 0; | |
37 // Called when the writer is unblocked due to a write completion. | |
38 virtual void OnWriteUnblocked() = 0; | |
34 }; | 39 }; |
35 | 40 |
36 QuicChromiumPacketWriter(); | 41 QuicChromiumPacketWriter(); |
37 explicit QuicChromiumPacketWriter(Socket* socket); | 42 explicit QuicChromiumPacketWriter(Socket* socket); |
Ryan Hamilton
2016/09/09 02:56:23
I assume socket must outlive the writer? If so, pl
Jana
2016/09/09 04:19:34
Yes. The socket that's passed in is owned by QuicC
| |
38 ~QuicChromiumPacketWriter() override; | 43 ~QuicChromiumPacketWriter() override; |
39 | 44 |
40 void Initialize(WriteErrorObserver* observer, QuicConnection* connection); | 45 void set_delegate(Delegate* delegate) { delegate_ = delegate; } |
Ryan Hamilton
2016/09/09 02:56:23
nit: Can you comment "// Must outlive the writer."
Jana
2016/09/09 04:19:34
Done.
| |
41 | 46 |
42 // Writes |packet| to the socket and returns the error code from the write. | 47 // Writes |packet| to the socket and returns the error code from the write. |
43 int WritePacketToSocket(StringIOBuffer* packet); | 48 int WritePacketToSocket(StringIOBuffer* packet); |
44 | 49 |
45 // QuicPacketWriter | 50 // QuicPacketWriter |
46 WriteResult WritePacket(const char* buffer, | 51 WriteResult WritePacket(const char* buffer, |
47 size_t buf_len, | 52 size_t buf_len, |
48 const IPAddress& self_address, | 53 const IPAddress& self_address, |
49 const IPEndPoint& peer_address, | 54 const IPEndPoint& peer_address, |
50 PerPacketOptions* options) override; | 55 PerPacketOptions* options) override; |
51 bool IsWriteBlockedDataBuffered() const override; | 56 bool IsWriteBlockedDataBuffered() const override; |
52 bool IsWriteBlocked() const override; | 57 bool IsWriteBlocked() const override; |
53 void SetWritable() override; | 58 void SetWritable() override; |
54 QuicByteCount GetMaxPacketSize(const IPEndPoint& peer_address) const override; | 59 QuicByteCount GetMaxPacketSize(const IPEndPoint& peer_address) const override; |
55 | 60 |
56 void OnWriteComplete(int rv); | 61 void OnWriteComplete(int rv); |
57 | 62 |
58 protected: | 63 protected: |
59 void set_write_blocked(bool is_blocked) { write_blocked_ = is_blocked; } | 64 void set_write_blocked(bool is_blocked) { write_blocked_ = is_blocked; } |
60 | 65 |
61 private: | 66 private: |
62 Socket* socket_; | 67 Socket* socket_; |
63 QuicConnection* connection_; | 68 Delegate* delegate_; |
Ryan Hamilton
2016/09/09 02:56:23
// Unowned.
(And above, assuming that's true)
Jana
2016/09/09 04:19:34
Done.
| |
64 WriteErrorObserver* observer_; | |
65 // When a write returns asynchronously, |packet_| stores the written | 69 // When a write returns asynchronously, |packet_| stores the written |
66 // packet until OnWriteComplete is called. | 70 // packet until OnWriteComplete is called. |
67 scoped_refptr<StringIOBuffer> packet_; | 71 scoped_refptr<StringIOBuffer> packet_; |
68 | 72 |
69 // Whether a write is currently in flight. | 73 // Whether a write is currently in flight. |
70 bool write_blocked_; | 74 bool write_blocked_; |
71 | 75 |
72 base::WeakPtrFactory<QuicChromiumPacketWriter> weak_factory_; | 76 base::WeakPtrFactory<QuicChromiumPacketWriter> weak_factory_; |
73 | 77 |
74 DISALLOW_COPY_AND_ASSIGN(QuicChromiumPacketWriter); | 78 DISALLOW_COPY_AND_ASSIGN(QuicChromiumPacketWriter); |
75 }; | 79 }; |
76 | 80 |
77 } // namespace net | 81 } // namespace net |
78 | 82 |
79 #endif // NET_QUIC_QUIC_CHROMIUM_PACKET_WRITER_H_ | 83 #endif // NET_QUIC_QUIC_CHROMIUM_PACKET_WRITER_H_ |
OLD | NEW |