From a848893d85cd027d831ba0ecae9dacef0a5f0605 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 30 Aug 2008 17:33:07 -0700 Subject: ringbuf: create a new struct rbvec instead of reusing struct iovec Using struct iovec means having to cast iov_base everywhere we want to do pointer arithmetic. Instead, just use rbvec which can be safely casted to iovec whenever we use the readv/writev functions. --- src/ringbuf.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/ringbuf.h') diff --git a/src/ringbuf.h b/src/ringbuf.h index 93f753897..6225fcadf 100644 --- a/src/ringbuf.h +++ b/src/ringbuf.h @@ -46,6 +46,12 @@ struct ringbuf { size_t size_mask; }; +/* remain binary-compatible with struct iovec declared in : */ +struct rbvec { + unsigned char *base; + size_t len; +}; + /** * Allocates a ringbuffer data structure of a specified size. The * caller must arrange for a call to ringbuf_free() to release @@ -69,7 +75,7 @@ void ringbuf_free(struct ringbuf * rb); /** * Fill a data structure with a description of the current readable * data held in the ringbuffer. This description is returned in a two - * element array of struct iovec. Two elements are needed + * element array of struct rbvec. Two elements are needed * because the data to be read may be split across the end of the * ringbuffer. * @@ -83,16 +89,16 @@ void ringbuf_free(struct ringbuf * rb); * its corresponding @a buf field. * * @param rb a pointer to the ringbuffer structure. - * @param vec a pointer to a 2 element array of struct iovec. + * @param vec a pointer to a 2 element array of struct rbvec. * * @return total number of bytes readable into both vec elements */ -size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec); +size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct rbvec * vec); /** * Fill a data structure with a description of the current writable * space in the ringbuffer. The description is returned in a two - * element array of struct iovec. Two elements are needed + * element array of struct rbvec. Two elements are needed * because the space available for writing may be split across the end * of the ringbuffer. * @@ -106,11 +112,11 @@ size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec); * the corresponding @a buf field. * * @param rb a pointer to the ringbuffer structure. - * @param vec a pointer to a 2 element array of struct iovec. + * @param vec a pointer to a 2 element array of struct rbvec. * * @return total number of bytes writable in both vec elements */ -size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec); +size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct rbvec * vec); /** * Read data from the ringbuffer. -- cgit v1.2.3