Updating trunk VERSION from 1014.0 to 1015.0
[chromium-blink-merge.git] / net / curvecp / circular_buffer.h
blob1c257f9617b43b53643abc04f77e6001fade8380
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
3 // found in the LICENSE file.
5 #ifndef NET_CURVECP_CIRCULAR_BUFFER_H_
6 #define NET_CURVECP_CIRCULAR_BUFFER_H_
7 #pragma once
9 namespace net {
11 // A circular buffer is a fixed sized buffer which can be read or written
12 class CircularBuffer {
13 public:
14 // Create a CircularBuffer with maximum size |capacity|.
15 explicit CircularBuffer(int capacity);
16 ~CircularBuffer();
18 int length() const { return length_; }
20 // Writes data into the circular buffer.
21 // |data| is the bytes to write.
22 // |length| is the number of bytes to write.
23 // Returns the number of bytes written, which may be less than |length| or
24 // 0 if no space is available in the buffer.
25 int write(const char* data, int length);
27 // Reads up to |length| bytes from the buffer into |data|.
28 // Returns the number of bytes read, or 0 if no data is available.
29 int read(char* data, int length);
31 private:
32 int capacity_;
33 int head_;
34 int length_;
35 char* buffer_;
38 } // namespace net
40 #endif // NET_CURVECP_CIRCULAR_BUFFER_H_