Change zap_buffer_read_loop() to always try to read the full amount of bytes we wanted to get; add zap_buffer_seek() to skip n bytes from the beginning of the buffer (zap_buffer_toss works relative to the current position only)
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@539 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
parent
8e25e1ef36
commit
048d021f40
|
@ -122,6 +122,13 @@ void zap_buffer_zero(zap_buffer_t *buffer);
|
||||||
*/
|
*/
|
||||||
void zap_buffer_destroy(zap_buffer_t **buffer);
|
void zap_buffer_destroy(zap_buffer_t **buffer);
|
||||||
|
|
||||||
|
/*! \brief Seek to offset from the beginning of the buffer
|
||||||
|
* \param buffer buffer to seek
|
||||||
|
* \param datalen offset in bytes
|
||||||
|
* \return new position
|
||||||
|
*/
|
||||||
|
zap_size_t zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
zap_size_t zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen);
|
zap_size_t zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen);
|
||||||
|
|
|
@ -108,6 +108,27 @@ zap_size_t zap_buffer_inuse(zap_buffer_t *buffer)
|
||||||
return buffer->used;
|
return buffer->used;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zap_size_t zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen)
|
||||||
|
{
|
||||||
|
zap_size_t reading = 0;
|
||||||
|
|
||||||
|
assert(buffer != NULL);
|
||||||
|
|
||||||
|
if (buffer->used < 1) {
|
||||||
|
buffer->used = 0;
|
||||||
|
return 0;
|
||||||
|
} else if (buffer->used >= datalen) {
|
||||||
|
reading = datalen;
|
||||||
|
} else {
|
||||||
|
reading = buffer->used;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer->used = buffer->actually_used - reading;
|
||||||
|
buffer->head = buffer->data + reading;
|
||||||
|
|
||||||
|
return reading;
|
||||||
|
}
|
||||||
|
|
||||||
zap_size_t zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen)
|
zap_size_t zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen)
|
||||||
{
|
{
|
||||||
zap_size_t reading = 0;
|
zap_size_t reading = 0;
|
||||||
|
@ -137,13 +158,13 @@ void zap_buffer_set_loops(zap_buffer_t *buffer, int loops)
|
||||||
zap_size_t zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t datalen)
|
zap_size_t zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t datalen)
|
||||||
{
|
{
|
||||||
zap_size_t len;
|
zap_size_t len;
|
||||||
if ((len = zap_buffer_read(buffer, data, datalen)) == 0) {
|
if ((len = zap_buffer_read(buffer, data, datalen)) < datalen) {
|
||||||
if (buffer->loops == 0) {
|
if (buffer->loops == 0) {
|
||||||
return 0;
|
return len;
|
||||||
}
|
}
|
||||||
buffer->head = buffer->data;
|
buffer->head = buffer->data;
|
||||||
buffer->used = buffer->actually_used;
|
buffer->used = buffer->actually_used;
|
||||||
len = zap_buffer_read(buffer, data, datalen);
|
len = zap_buffer_read(buffer, data + len, datalen - len);
|
||||||
buffer->loops--;
|
buffer->loops--;
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
|
|
Loading…
Reference in New Issue