| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_TOOLS_FLIP_SERVER_RING_BUFFER_H__ | 5 #ifndef NET_TOOLS_FLIP_SERVER_RING_BUFFER_H__ |
| 6 #define NET_TOOLS_FLIP_SERVER_RING_BUFFER_H__ | 6 #define NET_TOOLS_FLIP_SERVER_RING_BUFFER_H__ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "net/tools/balsa/buffer_interface.h" | 11 #include "net/tools/balsa/buffer_interface.h" |
| 11 | 12 |
| 12 namespace net { | 13 namespace net { |
| 13 | 14 |
| 14 // The ring buffer is a circular buffer, that is, reads or writes may wrap | 15 // The ring buffer is a circular buffer, that is, reads or writes may wrap |
| 15 // around the end of the linear memory contained by the class (and back to | 16 // around the end of the linear memory contained by the class (and back to |
| 16 // the beginning). This is a good choice when you want to use a fixed amount | 17 // the beginning). This is a good choice when you want to use a fixed amount |
| 17 // of buffering and don't want to be moving memory around a lot. | 18 // of buffering and don't want to be moving memory around a lot. |
| 18 // | 19 // |
| 19 // What is the penalty for using this over a normal, linear buffer? | 20 // What is the penalty for using this over a normal, linear buffer? |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 int read_idx() const { return read_idx_; } | 91 int read_idx() const { return read_idx_; } |
| 91 int write_idx() const { return write_idx_; } | 92 int write_idx() const { return write_idx_; } |
| 92 int bytes_used() const { return bytes_used_; } | 93 int bytes_used() const { return bytes_used_; } |
| 93 int buffer_size() const { return buffer_size_; } | 94 int buffer_size() const { return buffer_size_; } |
| 94 const char* buffer() const { return buffer_.get(); } | 95 const char* buffer() const { return buffer_.get(); } |
| 95 | 96 |
| 96 int set_read_idx(int idx) { return read_idx_ = idx; } | 97 int set_read_idx(int idx) { return read_idx_ = idx; } |
| 97 int set_write_idx(int idx) { return write_idx_ = idx; } | 98 int set_write_idx(int idx) { return write_idx_ = idx; } |
| 98 | 99 |
| 99 private: | 100 private: |
| 100 scoped_ptr<char[]> buffer_; | 101 std::unique_ptr<char[]> buffer_; |
| 101 int buffer_size_; | 102 int buffer_size_; |
| 102 int bytes_used_; | 103 int bytes_used_; |
| 103 int read_idx_; | 104 int read_idx_; |
| 104 int write_idx_; | 105 int write_idx_; |
| 105 | 106 |
| 106 RingBuffer(const RingBuffer&); | 107 RingBuffer(const RingBuffer&); |
| 107 void operator=(const RingBuffer&); | 108 void operator=(const RingBuffer&); |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 } // namespace net | 111 } // namespace net |
| 111 | 112 |
| 112 #endif // NET_TOOLS_FLIP_SERVER_RING_BUFFER_H__ | 113 #endif // NET_TOOLS_FLIP_SERVER_RING_BUFFER_H__ |
| OLD | NEW |