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

Side by Side Diff: remoting/base/buffered_socket_writer.h

Issue 1582583003: Fix BufferedSocketWriter to buffer everything before it starts writing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « no previous file | remoting/base/buffered_socket_writer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_ 5 #ifndef REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_
6 #define REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_ 6 #define REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_
7 7
8 #include <list> 8 #include <list>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 18 matching lines...) Expand all
29 WriteCallback; 29 WriteCallback;
30 typedef base::Callback<void(int)> WriteFailedCallback; 30 typedef base::Callback<void(int)> WriteFailedCallback;
31 31
32 static scoped_ptr<BufferedSocketWriter> CreateForSocket( 32 static scoped_ptr<BufferedSocketWriter> CreateForSocket(
33 net::Socket* socket, 33 net::Socket* socket,
34 const WriteFailedCallback& write_failed_callback); 34 const WriteFailedCallback& write_failed_callback);
35 35
36 BufferedSocketWriter(); 36 BufferedSocketWriter();
37 virtual ~BufferedSocketWriter(); 37 virtual ~BufferedSocketWriter();
38 38
39 // Initializes the writer. |write_callback| is called to write data to the 39 // Starts the writer. |write_callback| is called to write data to the
40 // socket. |write_failed_callback| is called when write operation fails. 40 // socket. |write_failed_callback| is called when write operation fails.
41 // Writing stops after the first failed write. 41 // Writing stops after the first failed write.
42 void Init(const WriteCallback& write_callback, 42 void Start(const WriteCallback& write_callback,
43 const WriteFailedCallback& write_failed_callback); 43 const WriteFailedCallback& write_failed_callback);
44 44
45 // Puts a new data chunk in the buffer. 45 // Puts a new data chunk in the buffer. If called before Start() then all data
46 // is buffered until Start().
46 void Write(const scoped_refptr<net::IOBufferWithSize>& buffer, 47 void Write(const scoped_refptr<net::IOBufferWithSize>& buffer,
47 const base::Closure& done_task); 48 const base::Closure& done_task);
48 49
49 // Returns true when there is data waiting to be written. 50 // Returns true when there is data waiting to be written.
50 bool has_data_pending() { return !queue_.empty(); } 51 bool has_data_pending() { return !queue_.empty(); }
51 52
52 private: 53 private:
53 struct PendingPacket; 54 struct PendingPacket;
54 typedef std::list<PendingPacket*> DataQueue; 55 typedef std::list<PendingPacket*> DataQueue;
55 56
56 // Returns true if the writer is closed due to an error.
57 bool is_closed();
58
59 void DoWrite(); 57 void DoWrite();
60 void HandleWriteResult(int result); 58 void HandleWriteResult(int result);
61 void OnWritten(int result); 59 void OnWritten(int result);
62 60
63 base::ThreadChecker thread_checker_; 61 base::ThreadChecker thread_checker_;
64 62
65 WriteCallback write_callback_; 63 WriteCallback write_callback_;
66 WriteFailedCallback write_failed_callback_; 64 WriteFailedCallback write_failed_callback_;
67 65
66 bool closed_ = false;
67
68 DataQueue queue_; 68 DataQueue queue_;
69 69
70 bool write_pending_ = false; 70 bool write_pending_ = false;
71 71
72 base::WeakPtrFactory<BufferedSocketWriter> weak_factory_; 72 base::WeakPtrFactory<BufferedSocketWriter> weak_factory_;
73 }; 73 };
74 74
75 } // namespace remoting 75 } // namespace remoting
76 76
77 #endif // REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_ 77 #endif // REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/base/buffered_socket_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698