Chromium Code Reviews| Index: net/filter/block_buffer.h |
| diff --git a/net/filter/block_buffer.h b/net/filter/block_buffer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c040a006c4d24129ced1d6137535fd8e0de53276 |
| --- /dev/null |
| +++ b/net/filter/block_buffer.h |
| @@ -0,0 +1,42 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_FILTER_BLOCK_BUFFER_H |
| +#define NET_FILTER_BLOCK_BUFFER_H |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "net/base/io_buffer.h" |
| + |
| +namespace net { |
| + |
| +// A refillable input buffer, wrapping an IOBuffer. |
| +// The |WasRefilled| and |WasDrained| methods are responsible for maintaining |
| +// this class's state machine. A client class should call |WasDrained| when |
| +// bytes are drained from the buffer, and |WasRefilled| when new bytes are |
| +// placed in the underlying IOBuffer. Note that it is an error to drain more |
| +// bytes than are available in the BlockBuffer or to refill the BlockBuffer when |
| +// its previous block is not completely drained. |
|
Randy Smith (Not in Mondays)
2016/03/09 23:03:56
suggestion: Put these last two requirements in ter
xunjieli
2016/04/20 19:16:09
Done.
|
| +class BlockBuffer { |
| + public: |
| + BlockBuffer(); |
| + ~BlockBuffer(); |
| + |
| + bool HasMoreBytes() const; |
| + void WasRefilled(size_t filled_bytes); |
| + void WasDrained(size_t drained_bytes); |
| + |
| + size_t size() const; |
| + char* bytes() const { return bytes_; } |
| + size_t bytes_left() const { return bytes_left_; } |
| + IOBuffer* buffer() { return buffer_.get(); } |
|
Randy Smith (Not in Mondays)
2016/03/09 23:03:55
I think it's important to document the distinction
xunjieli
2016/04/20 19:16:08
Done.
|
| + |
| + private: |
| + scoped_refptr<IOBuffer> buffer_; |
| + char* bytes_; |
| + size_t bytes_left_; |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_FILTER_BLOCK_BUFFER_H |