14192
|
1 /*
|
|
2 * @file circbuffer.h Buffer Utility Functions
|
|
3 * @ingroup core
|
|
4 *
|
|
5 * Gaim is the legal property of its developers, whose names are too numerous
|
|
6 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
7 * source distribution.
|
|
8 *
|
|
9 * This program is free software; you can redistribute it and/or modify
|
|
10 * it under the terms of the GNU General Public License as published by
|
|
11 * the Free Software Foundation; either version 2 of the License, or
|
|
12 * (at your option) any later version.
|
|
13 *
|
|
14 * This program is distributed in the hope that it will be useful,
|
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 * GNU General Public License for more details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU General Public License
|
|
20 * along with this program; if not, write to the Free Software
|
|
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
22 */
|
|
23 #ifndef _CIRCBUFFER_H
|
|
24 #define _CIRCBUFFER_H
|
|
25
|
|
26 #include <glib.h>
|
|
27
|
|
28 #ifdef __cplusplus
|
|
29 extern "C" {
|
|
30 #endif
|
|
31
|
|
32 typedef struct _GaimCircBuffer {
|
|
33
|
|
34 /** A pointer to the starting address of our chunk of memory. */
|
|
35 gchar *buffer;
|
|
36
|
|
37 /** The incremental amount to increase this buffer by when
|
|
38 * the buffer is not big enough to hold incoming data, in bytes. */
|
|
39 gsize growsize;
|
|
40
|
|
41 /** The length of this buffer, in bytes. */
|
|
42 gsize buflen;
|
|
43
|
|
44 /** The number of bytes of this buffer that contain unread data. */
|
|
45 gsize bufused;
|
|
46
|
|
47 /** A pointer to the next byte where new incoming data is
|
|
48 * buffered to. */
|
|
49 gchar *inptr;
|
|
50
|
|
51 /** A pointer to the next byte of buffered data that should be
|
|
52 * read by the consumer. */
|
|
53 gchar *outptr;
|
|
54
|
|
55 } GaimCircBuffer;
|
|
56
|
|
57 /**
|
|
58 * Creates a new circular buffer. This will not allocate any memory for the
|
|
59 * actual buffer until data is appended to it.
|
|
60 *
|
|
61 * @param growsize The amount that the buffer should grow the first time data
|
|
62 * is appended and every time more space is needed. Pass in
|
|
63 * "0" to use the default of 256 bytes.
|
|
64 *
|
|
65 * @return The new GaimCircBuffer. This should be freed with
|
|
66 * gaim_circ_buffer_destroy when you are done with it
|
|
67 */
|
|
68 GaimCircBuffer *gaim_circ_buffer_new(gsize growsize);
|
|
69
|
|
70 /**
|
|
71 * Dispose of the GaimCircBuffer and free any memory used by it (including any
|
|
72 * memory used by the internal buffer).
|
|
73 *
|
|
74 * @param buf The GaimCircBuffer to free
|
|
75 */
|
|
76 void gaim_circ_buffer_destroy(GaimCircBuffer *buf);
|
|
77
|
|
78 /**
|
|
79 * Append data to the GaimCircBuffer. This will grow the internal
|
|
80 * buffer to fit the added data, if needed.
|
|
81 *
|
|
82 * @param buf The GaimCircBuffer to which to append the data
|
|
83 * @param src pointer to the data to copy into the buffer
|
|
84 * @param len number of bytes to copy into the buffer
|
|
85 */
|
|
86 void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len);
|
|
87
|
|
88 /**
|
|
89 * Determine the maximum number of contiguous bytes that can be read from the
|
|
90 * GaimCircBuffer.
|
|
91 * Note: This may not be the total number of bytes that are buffered - a
|
|
92 * subsequent call after calling gaim_circ_buffer_mark_read() may indicate more
|
|
93 * data is available to read.
|
|
94 *
|
|
95 * @param buf the GaimCircBuffer for which to determine the maximum contiguous
|
|
96 * bytes that can be read.
|
|
97 *
|
|
98 * @return the number of bytes that can be read from the GaimCircBuffer
|
|
99 */
|
|
100 gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf);
|
|
101
|
|
102 /**
|
|
103 * Mark the number of bytes that have been read from the buffer.
|
|
104 *
|
|
105 * @param buf The GaimCircBuffer to mark bytes read from
|
|
106 * @param len The number of bytes to mark as read
|
|
107 *
|
|
108 * @return TRUE if we successfully marked the bytes as having been read, FALSE
|
|
109 * otherwise.
|
|
110 */
|
|
111 gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len);
|
|
112
|
|
113 #ifdef __cplusplus
|
|
114 }
|
|
115 #endif
|
|
116
|
|
117 #endif /* _CIRCBUFFER_H */
|