Chromium Code Reviews| 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_PROTOCOL_BUFFERED_SOCKET_WRITER_H_ | 5 #ifndef REMOTING_PROTOCOL_BUFFERED_SOCKET_WRITER_H_ |
| 6 #define REMOTING_PROTOCOL_BUFFERED_SOCKET_WRITER_H_ | 6 #define REMOTING_PROTOCOL_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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 | 60 |
| 61 protected: | 61 protected: |
| 62 class PendingPacket; | 62 class PendingPacket; |
| 63 typedef std::list<PendingPacket*> DataQueue; | 63 typedef std::list<PendingPacket*> DataQueue; |
| 64 | 64 |
| 65 DataQueue queue_; | 65 DataQueue queue_; |
| 66 int buffer_size_; | 66 int buffer_size_; |
| 67 | 67 |
| 68 // Removes element from the front of the queue and calls |done_task| | 68 // Removes element from the front of the queue and calls |done_task| |
| 69 // for that element. | 69 // for that element. |
| 70 void PopQueue(); | 70 base::Closure PopQueue(); |
| 71 | 71 |
|
simonmorris
2012/07/31 20:19:50
Maybe document what the caller may/should/must do
Sergey Ulanov
2012/07/31 21:37:53
Done.
| |
| 72 // Following three methods must be implemented in child classes. | 72 // Following three methods must be implemented in child classes. |
| 73 // GetNextPacket() returns next packet that needs to be written to the | 73 |
| 74 // socket. |buffer| must be set to NULL if there is nothing left in the queue. | 74 // Returns next packet that needs to be written to the socket. |buffer| must |
|
simonmorris
2012/07/31 20:19:50
"|buffer| must" -> "*buffer will"? "Must" sounds l
Sergey Ulanov
2012/07/31 21:37:53
Done.
| |
| 75 // be set to NULL if there is nothing left in the queue. | |
| 75 virtual void GetNextPacket(net::IOBuffer** buffer, int* size) = 0; | 76 virtual void GetNextPacket(net::IOBuffer** buffer, int* size) = 0; |
| 76 virtual void AdvanceBufferPosition(int written) = 0; | 77 |
| 78 // Returns closure that must be executed or null closure if the last write | |
| 79 // didn't complete any messages. | |
| 80 virtual base::Closure AdvanceBufferPosition(int written) = 0; | |
| 77 | 81 |
| 78 // This method is called whenever there is an error writing to the socket. | 82 // This method is called whenever there is an error writing to the socket. |
| 79 virtual void OnError(int result) = 0; | 83 virtual void OnError(int result) = 0; |
| 80 | 84 |
| 81 private: | 85 private: |
| 82 void DoWrite(); | 86 void DoWrite(); |
| 87 void HandleWriteResult(int result, bool* write_again); | |
| 83 void OnWritten(int result); | 88 void OnWritten(int result); |
| 84 | 89 |
| 85 // This method is called when an error is encountered. | 90 // This method is called when an error is encountered. |
| 86 void HandleError(int result); | 91 void HandleError(int result); |
| 87 | 92 |
| 88 net::Socket* socket_; | 93 net::Socket* socket_; |
| 89 WriteFailedCallback write_failed_callback_; | 94 WriteFailedCallback write_failed_callback_; |
| 90 | 95 |
| 91 bool write_pending_; | 96 bool write_pending_; |
| 92 | 97 |
| 93 bool closed_; | 98 bool closed_; |
| 99 | |
| 100 bool* destroyed_flag_; | |
| 94 }; | 101 }; |
| 95 | 102 |
| 96 class BufferedSocketWriter : public BufferedSocketWriterBase { | 103 class BufferedSocketWriter : public BufferedSocketWriterBase { |
| 97 public: | 104 public: |
| 98 BufferedSocketWriter(); | 105 BufferedSocketWriter(); |
| 99 virtual ~BufferedSocketWriter(); | 106 virtual ~BufferedSocketWriter(); |
| 100 | 107 |
| 101 protected: | 108 protected: |
| 102 virtual void GetNextPacket(net::IOBuffer** buffer, int* size) OVERRIDE; | 109 virtual void GetNextPacket(net::IOBuffer** buffer, int* size) OVERRIDE; |
| 103 virtual void AdvanceBufferPosition(int written) OVERRIDE; | 110 virtual base::Closure AdvanceBufferPosition(int written) OVERRIDE; |
| 104 virtual void OnError(int result) OVERRIDE; | 111 virtual void OnError(int result) OVERRIDE; |
| 105 | 112 |
| 106 private: | 113 private: |
| 107 scoped_refptr<net::DrainableIOBuffer> current_buf_; | 114 scoped_refptr<net::DrainableIOBuffer> current_buf_; |
| 108 }; | 115 }; |
| 109 | 116 |
| 110 class BufferedDatagramWriter : public BufferedSocketWriterBase { | 117 class BufferedDatagramWriter : public BufferedSocketWriterBase { |
| 111 public: | 118 public: |
| 112 BufferedDatagramWriter(); | 119 BufferedDatagramWriter(); |
| 113 virtual ~BufferedDatagramWriter(); | 120 virtual ~BufferedDatagramWriter(); |
| 114 | 121 |
| 115 protected: | 122 protected: |
| 116 virtual void GetNextPacket(net::IOBuffer** buffer, int* size) OVERRIDE; | 123 virtual void GetNextPacket(net::IOBuffer** buffer, int* size) OVERRIDE; |
| 117 virtual void AdvanceBufferPosition(int written) OVERRIDE; | 124 virtual base::Closure AdvanceBufferPosition(int written) OVERRIDE; |
| 118 virtual void OnError(int result) OVERRIDE; | 125 virtual void OnError(int result) OVERRIDE; |
| 119 }; | 126 }; |
| 120 | 127 |
| 121 } // namespace protocol | 128 } // namespace protocol |
| 122 } // namespace remoting | 129 } // namespace remoting |
| 123 | 130 |
| 124 #endif // REMOTING_PROTOCOL_BUFFERED_SOCKET_WRITER_H_ | 131 #endif // REMOTING_PROTOCOL_BUFFERED_SOCKET_WRITER_H_ |
| OLD | NEW |