mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2025-01-03 14:56:34 -05:00
Feature: Added code that can undo the effect of offsets
This commit is contained in:
parent
18e410cf24
commit
a92b39becd
18
src/buffer.c
18
src/buffer.c
@ -61,9 +61,20 @@ void buffer_preallocate(buffer_t *buffer, size_t request)
|
||||
void *n;
|
||||
size_t newlen;
|
||||
|
||||
/* TODO: use this function to clean up the effects of buffer->offset */
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
if (!buffer || !request)
|
||||
/* Remove the offset if it makes sense to do so. */
|
||||
if (buffer->offset == buffer->fill) {
|
||||
buffer->offset = 0;
|
||||
buffer->fill = 0;
|
||||
} else if ((2*buffer->offset) < buffer->fill || buffer->offset >= 512 || (buffer->offset > 128 && buffer->offset >= request)) {
|
||||
buffer->fill -= buffer->offset;
|
||||
memmove(buffer->buffer, buffer->buffer + buffer->offset, buffer->fill);
|
||||
buffer->offset = 0;
|
||||
}
|
||||
|
||||
if (!request)
|
||||
return;
|
||||
|
||||
newlen = buffer->fill + request;
|
||||
@ -145,6 +156,9 @@ int buffer_shift(buffer_t *buffer, size_t amount)
|
||||
|
||||
buffer->offset += amount;
|
||||
|
||||
/* run cleanup */
|
||||
buffer_preallocate(buffer, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user