106 new_buffer->
head = new_buffer->
data;
107 *buffer = new_buffer;
118 if ((new_buffer = malloc(
sizeof(*new_buffer)))) {
119 memset(new_buffer, 0,
sizeof(*new_buffer));
126 blocksize = start_len;
129 if (!(new_buffer->
data = malloc(start_len))) {
138 new_buffer->
datalen = start_len;
141 new_buffer->
head = new_buffer->
data;
144 *buffer = new_buffer;
204 if (buffer->
used < 1) {
207 }
else if (buffer->
used >= datalen) {
210 reading = buffer->
used;
213 buffer->
used -= reading;
214 buffer->
head += reading;
228 if (buffer->
loops > 0) {
231 if (buffer->
loops == 0) {
245 if (buffer->
used < 1) {
248 }
else if (buffer->
used >= datalen) {
251 reading = buffer->
used;
254 memcpy(data, buffer->
head, reading);
255 buffer->
used -= reading;
256 buffer->
head += reading;
265 if (buffer->
used < 1) {
268 }
else if (buffer->
used >= datalen) {
271 reading = buffer->
used;
274 memcpy(data, buffer->
head, reading);
283 if (buffer->
used < 1) {
288 reading = buffer->
used;
312 if (actual_freespace < datalen) {
321 if (freespace < datalen && (!buffer->
max_len || (buffer->
used + datalen <= buffer->
max_len))) {
328 if (new_block_size > new_size) {
329 new_size = new_block_size;
332 if (!(tmp = realloc(buffer->
data, new_size))) {
343 if (freespace < datalen) {
348 memcpy(buffer->
head + buffer->
used, data, datalen);
401 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 fspr_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)
#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)
struct fspr_pool_t switch_memory_pool_t
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.
void * switch_buffer_get_head_pointer(switch_buffer_t *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)