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

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

Issue 2319343004: Makes migration on write error asynchronous to avoid reentrancy issues (Closed)
Patch Set: synced and rebased 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"
(...skipping 14 matching lines...) Expand all
25 // Delegate interface which receives notifications on socket write events. 25 // Delegate interface which receives notifications on socket write events.
26 class NET_EXPORT_PRIVATE Delegate { 26 class NET_EXPORT_PRIVATE Delegate {
27 public: 27 public:
28 // Called when a socket write attempt results in a failure, so 28 // Called when a socket write attempt results in a failure, so
29 // that the delegate may recover from it by perhaps rewriting the 29 // that the delegate may recover from it by perhaps rewriting the
30 // packet to a different socket. An implementation must return the 30 // packet to a different socket. An implementation must return the
31 // return value from the rewrite attempt if there is one, and 31 // return value from the rewrite attempt if there is one, and
32 // |error_code| otherwise. 32 // |error_code| otherwise.
33 virtual int HandleWriteError(int error_code, 33 virtual int HandleWriteError(int error_code,
34 scoped_refptr<StringIOBuffer> last_packet) = 0; 34 scoped_refptr<StringIOBuffer> last_packet) = 0;
35
35 // Called to propagate the final write error to the delegate. 36 // Called to propagate the final write error to the delegate.
36 virtual void OnWriteError(int error_code) = 0; 37 virtual void OnWriteError(int error_code) = 0;
38
37 // Called when the writer is unblocked due to a write completion. 39 // Called when the writer is unblocked due to a write completion.
38 virtual void OnWriteUnblocked() = 0; 40 virtual void OnWriteUnblocked() = 0;
39 }; 41 };
40 42
41 QuicChromiumPacketWriter(); 43 QuicChromiumPacketWriter();
42 // |socket| must outlive writer. 44 // |socket| must outlive writer.
43 explicit QuicChromiumPacketWriter(Socket* socket); 45 explicit QuicChromiumPacketWriter(Socket* socket);
44 ~QuicChromiumPacketWriter() override; 46 ~QuicChromiumPacketWriter() override;
45 47
46 // |delegate| must outlive writer. 48 // |delegate| must outlive writer.
47 void set_delegate(Delegate* delegate) { delegate_ = delegate; } 49 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
48 50
51 void set_write_blocked(bool write_blocked) { write_blocked_ = write_blocked; }
52
49 // Writes |packet| to the socket and returns the error code from the write. 53 // Writes |packet| to the socket and returns the error code from the write.
50 int WritePacketToSocket(StringIOBuffer* packet); 54 WriteResult WritePacketToSocket(scoped_refptr<StringIOBuffer> packet);
51 55
52 // QuicPacketWriter 56 // QuicPacketWriter
53 WriteResult WritePacket(const char* buffer, 57 WriteResult WritePacket(const char* buffer,
54 size_t buf_len, 58 size_t buf_len,
55 const IPAddress& self_address, 59 const IPAddress& self_address,
56 const IPEndPoint& peer_address, 60 const IPEndPoint& peer_address,
57 PerPacketOptions* options) override; 61 PerPacketOptions* options) override;
58 bool IsWriteBlockedDataBuffered() const override; 62 bool IsWriteBlockedDataBuffered() const override;
59 bool IsWriteBlocked() const override; 63 bool IsWriteBlocked() const override;
60 void SetWritable() override; 64 void SetWritable() override;
61 QuicByteCount GetMaxPacketSize(const IPEndPoint& peer_address) const override; 65 QuicByteCount GetMaxPacketSize(const IPEndPoint& peer_address) const override;
62 66
63 void OnWriteComplete(int rv); 67 void OnWriteComplete(int rv);
64 68
65 protected:
66 void set_write_blocked(bool is_blocked) { write_blocked_ = is_blocked; }
67
68 private: 69 private:
69 Socket* socket_; // Unowned. 70 Socket* socket_; // Unowned.
70 Delegate* delegate_; // Unowned. 71 Delegate* delegate_; // Unowned.
71 // When a write returns asynchronously, |packet_| stores the written 72 // When a write returns asynchronously, |packet_| stores the written
72 // packet until OnWriteComplete is called. 73 // packet until OnWriteComplete is called.
73 scoped_refptr<StringIOBuffer> packet_; 74 scoped_refptr<StringIOBuffer> packet_;
74 75
75 // Whether a write is currently in flight. 76 // Whether a write is currently in flight.
76 bool write_blocked_; 77 bool write_blocked_;
77 78
78 base::WeakPtrFactory<QuicChromiumPacketWriter> weak_factory_; 79 base::WeakPtrFactory<QuicChromiumPacketWriter> weak_factory_;
79 80
80 DISALLOW_COPY_AND_ASSIGN(QuicChromiumPacketWriter); 81 DISALLOW_COPY_AND_ASSIGN(QuicChromiumPacketWriter);
81 }; 82 };
82 83
83 } // namespace net 84 } // namespace net
84 85
85 #endif // NET_QUIC_QUIC_CHROMIUM_PACKET_WRITER_H_ 86 #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