This patch gives direct access to cbuffers memory. Its essential to make glib's io read/write functions operate directly in the buffer instead using intermediate buffering or reading by one char. --- src/shared/cbuffer.c | 17 +++++++++++++++++ src/shared/cbuffer.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/src/shared/cbuffer.c b/src/shared/cbuffer.c index 7dde707..7fd95cc 100644 --- a/src/shared/cbuffer.c +++ b/src/shared/cbuffer.c @@ -122,3 +122,20 @@ unsigned int cbuffer_get_size(struct circular_buffer *cbuff) { return cbuff->size; } + +/* manual mode gives direct access to buffers memory space */ +char *cbuffer_get_free_cell(struct circular_buffer *cbuff) +{ + if (cbuffer_is_full(cbuff)) + return NULL; + return &(cbuff->data[cbuff->end & (cbuff->size - 1)]); +} + +int cbuffer_consume_next_cell(struct circular_buffer *cbuff) +{ + if (!cbuffer_is_full(cbuff)) { + cbuffer_incr(cbuff, &cbuff->end); + return 0; + } + return -ENOSPC; +} diff --git a/src/shared/cbuffer.h b/src/shared/cbuffer.h index 8865f1f..4aaacfa 100644 --- a/src/shared/cbuffer.h +++ b/src/shared/cbuffer.h @@ -31,3 +31,6 @@ void cbuffer_drain(struct circular_buffer *cbuff); int cbuffer_is_full(struct circular_buffer *cbuff); int cbuffer_is_empty(struct circular_buffer *cbuff); unsigned int cbuffer_get_size(struct circular_buffer *cbuff); +/* memory direct access functions */ +char *cbuffer_get_free_cell(struct circular_buffer *cbuff); +int cbuffer_consume_next_cell(struct circular_buffer *cbuff); -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html