1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
============================================================================
Name : hev-circular-buffer.h
Author : Heiher <r@hev.cc>
Copyright : Copyright (c) 2019 everyone.
Description : Circular buffer
============================================================================
*/
#ifndef __HEV_CIRCULAR_BUFFER_H__
#define __HEV_CIRCULAR_BUFFER_H__
#include <sys/uio.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _HevCircularBuffer HevCircularBuffer;
/**
* hev_circular_buffer_new:
* @max_size: max buffer size
*
* Creates a new circular buffer. The max buffer size is specified by @max_size.
*
* Returns: a new #HevCircularBuffer.
*
* Since: 4.6.1
*/
HevCircularBuffer *hev_circular_buffer_new (size_t max_size);
/**
* hev_circular_buffer_ref:
* @self: a #HevCircularBuffer
*
* Increases the reference count of the @self by one.
*
* Returns: a #HevCircularBuffer
*
* Since: 4.6.1
*/
HevCircularBuffer *hev_circular_buffer_ref (HevCircularBuffer *self);
/**
* hev_circular_buffer_unref:
* @self: a #HevCircularBuffer
*
* Decreases the reference count of @self. When its reference count
* drops to 0, the object is finalized (i.e. its memory is freed).
*
* Since: 4.6.1
*/
void hev_circular_buffer_unref (HevCircularBuffer *self);
/**
* hev_circular_buffer_get_max_size:
* @self: a #HevCircularBuffer
*
* Get the max size of buffer.
*
* Returns: the number of bytes actually allocated
*
* Since: 4.6.1
*/
size_t hev_circular_buffer_get_max_size (HevCircularBuffer *self);
/**
* hev_circular_buffer_get_use_size:
* @self: a #HevCircularBuffer
*
* Get the use size of buffer.
*
* Returns: the number of bytes actually used
*
* Since: 4.6.1
*/
size_t hev_circular_buffer_get_use_size (HevCircularBuffer *self);
/**
* hev_circular_buffer_reading:
* @self: a #HevCircularBuffer
* @iov: a io vector contain two elements
*
* The reading function start a buffer reading and update the @iov to point to
* data in buffer.
*
* Returns: the number of iov actually used
*
* Since: 4.6.1
*/
int hev_circular_buffer_reading (HevCircularBuffer *self, struct iovec *iov);
/**
* hev_circular_buffer_read_finish:
* @self: a #hevcircularbuffer
* @size: the number of bytes actually read
*
* the read_finish function stop buffer reading and increase read pointer by
* @size.
*
* returns: the number of iov actually used
*
* since: 4.6.1
*/
void hev_circular_buffer_read_finish (HevCircularBuffer *self, size_t size);
/**
* hev_circular_buffer_writing:
* @self: a #HevCircularBuffer
* @iov: a io vector contain two elements
*
* The writing function start a buffer writing and update the @iov to point to
* data in buffer.
*
* Returns: the number of iov actually used
*
* Since: 4.6.1
*/
int hev_circular_buffer_writing (HevCircularBuffer *self, struct iovec *iov);
/**
* hev_circular_buffer_write_finish:
* @self: a #hevcircularbuffer
* @size: the number of bytes actually write
*
* the write_finish function stop buffer writing and increase write pointer by
* @size.
*
* returns: the number of iov actually used
*
* since: 4.6.1
*/
void hev_circular_buffer_write_finish (HevCircularBuffer *self, size_t size);
#ifdef __cplusplus
}
#endif
#endif /* __HEV_CIRCULAR_BUFFER_H__ */