62 buffer->head = buffer->data;
63 buffer->used = buffer->actually_used = buffer->datalen;
75 buffer->datalen = datalen;
100 new_buffer->
head = new_buffer->
data;
101 *buffer = new_buffer;
112 if ((new_buffer = malloc(
sizeof(*new_buffer)))) {
113 memset(new_buffer, 0,
sizeof(*new_buffer));
116 if (!(new_buffer->
data = malloc(start_len))) {
125 new_buffer->
datalen = start_len;
128 new_buffer->
head = new_buffer->
data;
131 *buffer = new_buffer;
140 buffer->mutex =
mutex;
167 return buffer->datalen;
173 if (buffer->max_len) {
191 if (buffer->used < 1) {
194 }
else if (buffer->used >= datalen) {
197 reading = buffer->used;
200 buffer->used -= reading;
201 buffer->head += reading;
208 buffer->loops = loops;
215 if (buffer->loops > 0) {
218 if (buffer->loops == 0) {
221 buffer->head = buffer->data;
222 buffer->used = buffer->actually_used;
232 if (buffer->used < 1) {
235 }
else if (buffer->used >= datalen) {
238 reading = buffer->used;
241 memcpy(data, buffer->head, reading);
242 buffer->used -= reading;
243 buffer->head += reading;
252 if (buffer->used < 1) {
255 }
else if (buffer->used >= datalen) {
258 reading = buffer->used;
261 memcpy(data, buffer->head, reading);
270 if (buffer->used < 1) {
275 reading = buffer->used;
297 actual_freespace = buffer->datalen - buffer->actually_used;
299 if (actual_freespace < datalen) {
300 memmove(buffer->data, buffer->head, buffer->used);
301 buffer->head = buffer->data;
302 buffer->actually_used = buffer->used;
305 freespace = buffer->datalen - buffer->used;
308 if (freespace < datalen && (!buffer->max_len || (buffer->used + datalen <= buffer->max_len))) {
312 new_size = buffer->datalen + datalen;
313 new_block_size = buffer->datalen + buffer->blocksize;
315 if (new_block_size > new_size) {
316 new_size = new_block_size;
318 buffer->head = buffer->data;
319 if (!(tmp = realloc(buffer->data, new_size))) {
323 buffer->head = buffer->data;
324 buffer->datalen = new_size;
328 freespace = buffer->datalen - buffer->used;
330 if (freespace < datalen) {
334 memcpy(buffer->head + buffer->used, data, datalen);
335 buffer->used += datalen;
336 buffer->actually_used += datalen;
345 buffer->actually_used = 0;
346 buffer->head = buffer->data;
383 if (buffer && *buffer) {
switch_size_t actually_used
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
switch_size_t switch_buffer_peek_zerocopy(switch_buffer_t *buffer, const void **ptr)
switch_memory_pool_t * pool
void switch_buffer_unlock(switch_buffer_t *buffer)
switch_size_t switch_buffer_slide_write(switch_buffer_t *buffer, const void *data, switch_size_t datalen)
switch_size_t switch_buffer_freespace(switch_buffer_t *buffer)
switch_status_t switch_buffer_create(switch_memory_pool_t *pool, switch_buffer_t **buffer, switch_size_t max_len)
void switch_buffer_lock(switch_buffer_t *buffer)
switch_size_t switch_buffer_inuse(switch_buffer_t *buffer)
switch_status_t switch_buffer_create_partition(switch_memory_pool_t *pool, switch_buffer_t **buffer, void *data, switch_size_t datalen)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
static uint32_t buffer_id
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
switch_status_t switch_buffer_trylock(switch_buffer_t *buffer)
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
switch_size_t switch_buffer_toss(switch_buffer_t *buffer, switch_size_t datalen)
switch_size_t switch_buffer_peek(switch_buffer_t *buffer, void *data, switch_size_t datalen)
void switch_buffer_add_mutex(switch_buffer_t *buffer, switch_mutex_t *mutex)
struct apr_thread_mutex_t switch_mutex_t
switch_status_t
Common return values.
switch_status_t switch_buffer_reset_partition_data(switch_buffer_t *buffer)
switch_size_t switch_buffer_read_loop(switch_buffer_t *buffer, void *data, switch_size_t datalen)
switch_size_t switch_buffer_zwrite(switch_buffer_t *buffer, const void *data, switch_size_t datalen)
switch_size_t switch_buffer_len(switch_buffer_t *buffer)
struct apr_pool_t switch_memory_pool_t
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
void switch_buffer_set_loops(switch_buffer_t *buffer, int32_t loops)
switch_status_t switch_buffer_set_partition_data(switch_buffer_t *buffer, void *data, switch_size_t datalen)
switch_size_t switch_buffer_read(switch_buffer_t *buffer, void *data, switch_size_t datalen)
void switch_buffer_destroy(switch_buffer_t **buffer)
Destroy the buffer.
switch_size_t switch_buffer_write(switch_buffer_t *buffer, const void *data, switch_size_t datalen)
switch_status_t switch_buffer_create_dynamic(switch_buffer_t **buffer, switch_size_t blocksize, switch_size_t start_len, switch_size_t max_len)
void switch_buffer_zero(switch_buffer_t *buffer)