mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2025-02-02 15:07:36 -05:00
Feature: Added a way to push buffers into buffers
This commit is contained in:
parent
71b156afc6
commit
934cc32285
16
src/buffer.c
16
src/buffer.c
@ -264,6 +264,22 @@ int buffer_push_vprintf(buffer_t *buffer, const char *format, va_list ap
|
||||
return buffer_zerocopy_push_complete(buffer, ret);
|
||||
}
|
||||
|
||||
int buffer_push_buffer(buffer_t *buffer, buffer_t *source)
|
||||
{
|
||||
const void *data;
|
||||
size_t length;
|
||||
int ret;
|
||||
|
||||
if (!buffer || !source)
|
||||
return -1;
|
||||
|
||||
ret = buffer_get_data(source, &data, &length);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
return buffer_push_data(buffer, data, length);
|
||||
}
|
||||
|
||||
int buffer_zerocopy_push_request(buffer_t *buffer, void **data, size_t request)
|
||||
{
|
||||
if (!buffer || !data)
|
||||
|
@ -153,6 +153,15 @@ int buffer_push_printf(buffer_t *buffer, const char *format, ...);
|
||||
*/
|
||||
int buffer_push_vprintf(buffer_t *buffer, const char *format, va_list ap);
|
||||
|
||||
/* This pushes the content of another buffer to the end of the buffer.
|
||||
* Parameters:
|
||||
* buffer
|
||||
* The buffer to operate on.
|
||||
* source
|
||||
* The buffer which's content is to be copied.
|
||||
*/
|
||||
int buffer_push_buffer(buffer_t *buffer, buffer_t *source);
|
||||
|
||||
/* This requests for a memory buffer that can be pushed to without the need for copy.
|
||||
* Parameters:
|
||||
* buffer
|
||||
|
@ -303,6 +303,31 @@ static void test_printf(void)
|
||||
ctest_test("un-referenced", refobject_unref(a) == 0);
|
||||
}
|
||||
|
||||
static void test_push_buffer(void)
|
||||
{
|
||||
buffer_t *a;
|
||||
buffer_t *b;
|
||||
const char *pattern = "AABBBCC";
|
||||
const char *match_a = "AABBBCCAABBBCC";
|
||||
|
||||
a = buffer_new_simple();
|
||||
ctest_test("buffer a created", a != NULL);
|
||||
b = buffer_new_simple();
|
||||
ctest_test("buffer b created", b != NULL);
|
||||
|
||||
ctest_test("pushed string", buffer_push_string(a, pattern) == 0);
|
||||
test__compare_to_string(a, "string matches input", pattern);
|
||||
|
||||
ctest_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0);
|
||||
test__compare_to_string(b, "string matches input", pattern);
|
||||
|
||||
ctest_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0);
|
||||
test__compare_to_string(b, "string matches pattern a", match_a);
|
||||
|
||||
ctest_test("un-referenced b", refobject_unref(b) == 0);
|
||||
ctest_test("un-referenced a", refobject_unref(a) == 0);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
ctest_init();
|
||||
@ -322,6 +347,7 @@ int main (void)
|
||||
test_length();
|
||||
|
||||
test_printf();
|
||||
test_push_buffer();
|
||||
|
||||
ctest_fin();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user