Fix behavior of evbuffer_peek(buf,-1,NULL,NULL,0)

(Patch altered by nickm to not affect the behavior of
evbuffer_peek(buf,-1,NULL,vec,n_vec).)
This commit is contained in:
Zack Weinberg 2011-12-08 14:30:20 -05:00 committed by Nick Mathewson
parent 358c745e54
commit c986f2321d
2 changed files with 12 additions and 1 deletions

View File

@ -2582,14 +2582,21 @@ evbuffer_peek(struct evbuffer *buffer, ev_ssize_t len,
chain = buffer->first;
}
if (n_vec == 0 && len < 0) {
/* If no vectors are provided and they asked for "everything",
* pretend they asked for the actual available amount. */
len = buffer->total_len - len_so_far;
}
while (chain) {
if (len >= 0 && len_so_far >= len)
break;
if (idx<n_vec) {
vec[idx].iov_base = chain->buffer + chain->misalign;
vec[idx].iov_len = chain->off;
} else if (len<0)
} else if (len<0) {
break;
}
++idx;
len_so_far += chain->off;
chain = chain->next;

View File

@ -1441,6 +1441,10 @@ test_evbuffer_peek(void *info)
evbuffer_add_buffer(buf, tmp_buf);
}
/* How many chunks do we need for everything? */
i = evbuffer_peek(buf, -1, NULL, NULL, 0);
tt_int_op(i, ==, 16);
/* Simple peek: get everything. */
i = evbuffer_peek(buf, -1, NULL, v, 20);
tt_int_op(i, ==, 16); /* we used only 16 chunks. */