From 41f7ac7387fbfa5b1519ac5e5a73b7aac11feca0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 30 Oct 2009 22:53:09 +0000 Subject: [PATCH] add slide_write to switch_buffer git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15297 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_buffer.h | 2 ++ src/switch_buffer.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/include/switch_buffer.h b/src/include/switch_buffer.h index f2dd8a9daf..f31663989a 100644 --- a/src/include/switch_buffer.h +++ b/src/include/switch_buffer.h @@ -137,6 +137,8 @@ SWITCH_DECLARE(switch_size_t) switch_buffer_toss(_In_ switch_buffer_t *buffer, _ */ SWITCH_DECLARE(void) switch_buffer_zero(_In_ switch_buffer_t *buffer); +SWITCH_DECLARE(switch_size_t) switch_buffer_slide_write(switch_buffer_t *buffer, const void *data, switch_size_t datalen); + /*! \brief Destroy the buffer * \param buffer buffer to destroy * \note only neccessary on dynamic buffers (noop on pooled ones) diff --git a/src/switch_buffer.c b/src/switch_buffer.c index e7700745ad..dc91a6539d 100644 --- a/src/switch_buffer.c +++ b/src/switch_buffer.c @@ -280,6 +280,18 @@ SWITCH_DECLARE(switch_size_t) switch_buffer_zwrite(switch_buffer_t *buffer, cons return w; } +SWITCH_DECLARE(switch_size_t) switch_buffer_slide_write(switch_buffer_t *buffer, const void *data, switch_size_t datalen) +{ + switch_size_t w; + + if (!(w = switch_buffer_write(buffer, data, datalen))) { + switch_buffer_toss(buffer, datalen); + return switch_buffer_write(buffer, data, datalen); + } + + return w; +} + SWITCH_DECLARE(void) switch_buffer_destroy(switch_buffer_t **buffer) { if (buffer && *buffer) {