aboutsummaryrefslogtreecommitdiffstats
path: root/src/ringbuf.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-06-30 02:42:55 +0000
committerEric Wong <normalperson@yhbt.net>2008-06-30 02:42:55 +0000
commit9873e07c5abf787d7805b4266a243e56240354dc (patch)
tree033498fb06470eb882c97fcedf52dc3f532fbbf8 /src/ringbuf.c
parentaa828c1b2576f19a7d0de11a791ecd7f93c206dc (diff)
downloadmpd-9873e07c5abf787d7805b4266a243e56240354dc.tar.gz
mpd-9873e07c5abf787d7805b4266a243e56240354dc.tar.xz
mpd-9873e07c5abf787d7805b4266a243e56240354dc.zip
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
Diffstat (limited to '')
-rw-r--r--src/ringbuf.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/ringbuf.c b/src/ringbuf.c
index 517a4c216..569a70757 100644
--- a/src/ringbuf.c
+++ b/src/ringbuf.c
@@ -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
* 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 cnt2;
@@ -247,13 +247,13 @@ void ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec)
vec[0].iov_len = rb->size - r;
vec[1].iov_base = rb->buf;
vec[1].iov_len = cnt2 & rb->size_mask;
-
} else {
/* Single part vector: just the rest of the buffer */
vec[0].iov_base = rb->buf + r;
vec[0].iov_len = free_cnt;
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)
* the writeable data is in one segment the second segment has zero
* 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 cnt2;
@@ -292,5 +292,6 @@ void ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec)
vec[0].iov_len = free_cnt;
vec[1].iov_len = 0;
}
+ return vec[0].iov_len + vec[1].iov_len;
}