mirror of
https://gitlab.xiph.org/xiph/icecast-common.git
synced 2024-12-04 14:46:31 -05:00
Feature: Added igloo_io_peek()
This commit is contained in:
parent
bb081672f4
commit
ed52c31b11
@ -106,6 +106,7 @@ typedef struct {
|
|||||||
igloo_interface_base_ifdesc_t __base;
|
igloo_interface_base_ifdesc_t __base;
|
||||||
|
|
||||||
ssize_t (*read)(igloo_INTERFACE_BASIC_ARGS, void *buffer, size_t len, igloo_error_t *error);
|
ssize_t (*read)(igloo_INTERFACE_BASIC_ARGS, void *buffer, size_t len, igloo_error_t *error);
|
||||||
|
ssize_t (*peek)(igloo_INTERFACE_BASIC_ARGS, void *buffer, size_t len, igloo_error_t *error);
|
||||||
ssize_t (*write)(igloo_INTERFACE_BASIC_ARGS, const void *buffer, size_t len, igloo_error_t *error);
|
ssize_t (*write)(igloo_INTERFACE_BASIC_ARGS, const void *buffer, size_t len, igloo_error_t *error);
|
||||||
igloo_error_t (*flush)(igloo_INTERFACE_BASIC_ARGS, igloo_io_opflag_t flags);
|
igloo_error_t (*flush)(igloo_INTERFACE_BASIC_ARGS, igloo_io_opflag_t flags);
|
||||||
igloo_error_t (*sync)(igloo_INTERFACE_BASIC_ARGS, igloo_io_opflag_t flags);
|
igloo_error_t (*sync)(igloo_INTERFACE_BASIC_ARGS, igloo_io_opflag_t flags);
|
||||||
@ -144,6 +145,13 @@ igloo_io_t * igloo_io_new(const igloo_io_ifdesc_t *ifdesc, igloo_ro_t backend_ob
|
|||||||
* The actual amount of bytes read.
|
* The actual amount of bytes read.
|
||||||
*/
|
*/
|
||||||
ssize_t igloo_io_read(igloo_io_t *io, void *buffer, size_t len, igloo_error_t *error);
|
ssize_t igloo_io_read(igloo_io_t *io, void *buffer, size_t len, igloo_error_t *error);
|
||||||
|
|
||||||
|
/* Peeks on the input side of the handle.
|
||||||
|
*
|
||||||
|
* This does the same as igloo_io_read() expect that the data is not removed from the read queue.
|
||||||
|
* This is likely not to be supported by some backends.
|
||||||
|
*/
|
||||||
|
ssize_t igloo_io_peek(igloo_io_t *io, void *buffer, size_t len, igloo_error_t *error);
|
||||||
/* Write data to a IO handle.
|
/* Write data to a IO handle.
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* io
|
* io
|
||||||
|
49
src/io.c
49
src/io.c
@ -58,31 +58,34 @@ igloo_io_t * igloo_io_new(const igloo_io_ifdesc_t *ifdesc, igloo_ro_t backend_ob
|
|||||||
return io;
|
return io;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define __read_fun(x) \
|
||||||
ssize_t igloo_io_read(igloo_io_t *io, void *buffer, size_t len, igloo_error_t *error)
|
ssize_t igloo_io_ ## x (igloo_io_t *io, void *buffer, size_t len, igloo_error_t *error) \
|
||||||
{
|
{ \
|
||||||
ssize_t ret = -1;
|
ssize_t ret = -1; \
|
||||||
igloo_error_t error_store;
|
igloo_error_t error_store; \
|
||||||
|
\
|
||||||
if (!io || !buffer)
|
if (!io || !buffer) \
|
||||||
return -1;
|
return -1; \
|
||||||
|
\
|
||||||
if (!len)
|
if (!len) \
|
||||||
return 0;
|
return 0; \
|
||||||
|
\
|
||||||
if (!error)
|
if (!error) \
|
||||||
error = &error_store;
|
error = &error_store; \
|
||||||
|
\
|
||||||
igloo_thread_mutex_lock(&(io->lock));
|
igloo_thread_mutex_lock(&(io->lock)); \
|
||||||
io->touched = 1;
|
io->touched = 1; \
|
||||||
|
\
|
||||||
if (io->ifdesc->read)
|
if (io->ifdesc->x) \
|
||||||
ret = io->ifdesc->read(igloo_INTERFACE_BASIC_CALL(io), buffer, len, error);
|
ret = io->ifdesc->x(igloo_INTERFACE_BASIC_CALL(io), buffer, len, error); \
|
||||||
igloo_thread_mutex_unlock(&(io->lock));
|
igloo_thread_mutex_unlock(&(io->lock)); \
|
||||||
|
\
|
||||||
return ret;
|
return ret; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__read_fun(read)
|
||||||
|
__read_fun(peek)
|
||||||
|
|
||||||
ssize_t igloo_io_write(igloo_io_t *io, const void *buffer, size_t len, igloo_error_t *error)
|
ssize_t igloo_io_write(igloo_io_t *io, const void *buffer, size_t len, igloo_error_t *error)
|
||||||
{
|
{
|
||||||
ssize_t ret = -1;
|
ssize_t ret = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user