OLD | NEW |
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 24 matching lines...) Expand all Loading... |
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 // Initializes 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 Init(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. Returns false if writing has stopped | 45 // Puts a new data chunk in the buffer. |
46 // because of an error. | 46 void Write(const scoped_refptr<net::IOBufferWithSize>& buffer, |
47 bool Write(const scoped_refptr<net::IOBufferWithSize>& buffer, | |
48 const base::Closure& done_task); | 47 const base::Closure& done_task); |
49 | 48 |
50 // Returns true when there is data waiting to be written. | 49 // Returns true when there is data waiting to be written. |
51 bool has_data_pending() { return !queue_.empty(); } | 50 bool has_data_pending() { return !queue_.empty(); } |
52 | 51 |
53 private: | 52 private: |
54 struct PendingPacket; | 53 struct PendingPacket; |
55 typedef std::list<PendingPacket*> DataQueue; | 54 typedef std::list<PendingPacket*> DataQueue; |
56 | 55 |
57 // Returns true if the writer is closed due to an error. | 56 // Returns true if the writer is closed due to an error. |
(...skipping 11 matching lines...) Expand all Loading... |
69 DataQueue queue_; | 68 DataQueue queue_; |
70 | 69 |
71 bool write_pending_ = false; | 70 bool write_pending_ = false; |
72 | 71 |
73 base::WeakPtrFactory<BufferedSocketWriter> weak_factory_; | 72 base::WeakPtrFactory<BufferedSocketWriter> weak_factory_; |
74 }; | 73 }; |
75 | 74 |
76 } // namespace remoting | 75 } // namespace remoting |
77 | 76 |
78 #endif // REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_ | 77 #endif // REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_ |
OLD | NEW |