Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: net/quic/chromium/quic_chromium_packet_writer.h

Issue 2325733004: Makes QuicChromiumPacketWriter use the delegate for interacting with the connection. (Closed)
Patch Set: Nits fixed. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 the final write error to the delegate.
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();
42 // |socket| must outlive writer.
37 explicit QuicChromiumPacketWriter(Socket* socket); 43 explicit QuicChromiumPacketWriter(Socket* socket);
38 ~QuicChromiumPacketWriter() override; 44 ~QuicChromiumPacketWriter() override;
39 45
40 void Initialize(WriteErrorObserver* observer, QuicConnection* connection); 46 // |delegate| must outlive writer.
47 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
41 48
42 // Writes |packet| to the socket and returns the error code from the write. 49 // Writes |packet| to the socket and returns the error code from the write.
43 int WritePacketToSocket(StringIOBuffer* packet); 50 int WritePacketToSocket(StringIOBuffer* packet);
44 51
45 // QuicPacketWriter 52 // QuicPacketWriter
46 WriteResult WritePacket(const char* buffer, 53 WriteResult WritePacket(const char* buffer,
47 size_t buf_len, 54 size_t buf_len,
48 const IPAddress& self_address, 55 const IPAddress& self_address,
49 const IPEndPoint& peer_address, 56 const IPEndPoint& peer_address,
50 PerPacketOptions* options) override; 57 PerPacketOptions* options) override;
51 bool IsWriteBlockedDataBuffered() const override; 58 bool IsWriteBlockedDataBuffered() const override;
52 bool IsWriteBlocked() const override; 59 bool IsWriteBlocked() const override;
53 void SetWritable() override; 60 void SetWritable() override;
54 QuicByteCount GetMaxPacketSize(const IPEndPoint& peer_address) const override; 61 QuicByteCount GetMaxPacketSize(const IPEndPoint& peer_address) const override;
55 62
56 void OnWriteComplete(int rv); 63 void OnWriteComplete(int rv);
57 64
58 protected: 65 protected:
59 void set_write_blocked(bool is_blocked) { write_blocked_ = is_blocked; } 66 void set_write_blocked(bool is_blocked) { write_blocked_ = is_blocked; }
60 67
61 private: 68 private:
62 Socket* socket_; 69 Socket* socket_; // Unowned.
63 QuicConnection* connection_; 70 Delegate* delegate_; // Unowned.
64 WriteErrorObserver* observer_;
65 // When a write returns asynchronously, |packet_| stores the written 71 // When a write returns asynchronously, |packet_| stores the written
66 // packet until OnWriteComplete is called. 72 // packet until OnWriteComplete is called.
67 scoped_refptr<StringIOBuffer> packet_; 73 scoped_refptr<StringIOBuffer> packet_;
68 74
69 // Whether a write is currently in flight. 75 // Whether a write is currently in flight.
70 bool write_blocked_; 76 bool write_blocked_;
71 77
72 base::WeakPtrFactory<QuicChromiumPacketWriter> weak_factory_; 78 base::WeakPtrFactory<QuicChromiumPacketWriter> weak_factory_;
73 79
74 DISALLOW_COPY_AND_ASSIGN(QuicChromiumPacketWriter); 80 DISALLOW_COPY_AND_ASSIGN(QuicChromiumPacketWriter);
75 }; 81 };
76 82
77 } // namespace net 83 } // namespace net
78 84
79 #endif // NET_QUIC_QUIC_CHROMIUM_PACKET_WRITER_H_ 85 #endif // NET_QUIC_QUIC_CHROMIUM_PACKET_WRITER_H_
OLDNEW
« no previous file with comments | « net/quic/chromium/quic_chromium_client_session_test.cc ('k') | net/quic/chromium/quic_chromium_packet_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698