shl: ring: provide offset parameter for shl_ring_peek()

If we want to fill a whole buffer, we actually might have to read more
data than just the data from the beginning. Therefore, provide an offset
so we can read from multiple pages.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-10-25 14:47:32 +02:00
parent a0a9a7f9b4
commit eaffe90061
2 changed files with 23 additions and 6 deletions

View File

@ -367,7 +367,7 @@ static int send_buf(struct kmscon_pty *pty)
size_t len;
int ret;
while ((buf = shl_ring_peek(pty->msgbuf, &len))) {
while ((buf = shl_ring_peek(pty->msgbuf, &len, 0))) {
ret = write(pty->fd, buf, len);
if (ret > 0) {
shl_ring_drop(pty->msgbuf, ret);

View File

@ -131,13 +131,30 @@ next:
return 0;
}
static inline const char *shl_ring_peek(struct shl_ring *ring, size_t *len)
static inline const char *shl_ring_peek(struct shl_ring *ring, size_t *len,
size_t offset)
{
if (!ring || !ring->first)
return NULL;
struct shl_ring_entry *iter;
*len = ring->first->len;
return ring->first->buf;
if (!ring || !ring->first || !len) {
if (len)
*len = 0;
return NULL;
}
iter = ring->first;
while (iter->len <= offset) {
if (!iter->next) {
*len = 0;
return NULL;
}
offset -= iter->len;
iter = iter->next;
}
*len = ring->first->len - offset;
return &ring->first->buf[offset];
}
static inline void shl_ring_drop(struct shl_ring *ring, size_t len)