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_
11 // A circular buffer is a fixed sized buffer which can be read or written
12 class CircularBuffer
{
14 // Create a CircularBuffer with maximum size |capacity|.
15 explicit CircularBuffer(int capacity
);
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
);
40 #endif // NET_CURVECP_CIRCULAR_BUFFER_H_