Commit 9873e07c authored by Eric Wong's avatar Eric Wong

ringbuf: get_{write,read}_vector returns total bytes in both vec elts

This will eliminate unnecessary calls to ringbuf_{read,write}_space git-svn-id: https://svn.musicpd.org/mpd/trunk@7389 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent aa828c1b
...@@ -224,7 +224,7 @@ void ringbuf_write_advance(struct ringbuf * rb, size_t cnt) ...@@ -224,7 +224,7 @@ void ringbuf_write_advance(struct ringbuf * rb, size_t cnt)
* the readable data is in one segment the second segment has zero * the readable data is in one segment the second segment has zero
* length. * length.
*/ */
void ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec) size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec)
{ {
size_t free_cnt; size_t free_cnt;
size_t cnt2; size_t cnt2;
...@@ -247,13 +247,13 @@ void ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec) ...@@ -247,13 +247,13 @@ void ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec)
vec[0].iov_len = rb->size - r; vec[0].iov_len = rb->size - r;
vec[1].iov_base = rb->buf; vec[1].iov_base = rb->buf;
vec[1].iov_len = cnt2 & rb->size_mask; vec[1].iov_len = cnt2 & rb->size_mask;
} else { } else {
/* Single part vector: just the rest of the buffer */ /* Single part vector: just the rest of the buffer */
vec[0].iov_base = rb->buf + r; vec[0].iov_base = rb->buf + r;
vec[0].iov_len = free_cnt; vec[0].iov_len = free_cnt;
vec[1].iov_len = 0; vec[1].iov_len = 0;
} }
return vec[0].iov_len + vec[1].iov_len;
} }
/* /*
...@@ -262,7 +262,7 @@ void ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec) ...@@ -262,7 +262,7 @@ void ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec)
* the writeable data is in one segment the second segment has zero * the writeable data is in one segment the second segment has zero
* length. * length.
*/ */
void ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec) size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec)
{ {
size_t free_cnt; size_t free_cnt;
size_t cnt2; size_t cnt2;
...@@ -292,5 +292,6 @@ void ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec) ...@@ -292,5 +292,6 @@ void ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec)
vec[0].iov_len = free_cnt; vec[0].iov_len = free_cnt;
vec[1].iov_len = 0; vec[1].iov_len = 0;
} }
return vec[0].iov_len + vec[1].iov_len;
} }
...@@ -85,8 +85,9 @@ void ringbuf_free(struct ringbuf * rb); ...@@ -85,8 +85,9 @@ void ringbuf_free(struct ringbuf * rb);
* @param rb a pointer to the ringbuffer structure. * @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 iovec.
* *
* @return total number of bytes readable into both vec elements
*/ */
void ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec); size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec);
/** /**
* Fill a data structure with a description of the current writable * Fill a data structure with a description of the current writable
...@@ -106,8 +107,10 @@ void ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec); ...@@ -106,8 +107,10 @@ void ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec);
* *
* @param rb a pointer to the ringbuffer structure. * @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 iovec.
*
* @return total number of bytes writable in both vec elements
*/ */
void ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec); size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec);
/** /**
* Read data from the ringbuffer. * Read data from the ringbuffer.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment