Merge remote-tracking branch 'origin/patches-2.0'

This commit is contained in:
Nick Mathewson 2011-12-08 14:38:04 -05:00
commit cac02fadc2
3 changed files with 16 additions and 3 deletions

View File

@ -2734,14 +2734,21 @@ evbuffer_peek(struct evbuffer *buffer, ev_ssize_t len,
chain = buffer->first; 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) { while (chain) {
if (len >= 0 && len_so_far >= len) if (len >= 0 && len_so_far >= len)
break; break;
if (idx<n_vec) { if (idx<n_vec) {
vec[idx].iov_base = chain->buffer + chain->misalign; vec[idx].iov_base = chain->buffer + chain->misalign;
vec[idx].iov_len = chain->off; vec[idx].iov_len = chain->off;
} else if (len<0) } else if (len<0) {
break; break;
}
++idx; ++idx;
len_so_far += chain->off; len_so_far += chain->off;
chain = chain->next; chain = chain->next;

View File

@ -779,8 +779,10 @@ struct evbuffer_ptr evbuffer_search_eol(struct evbuffer *buffer,
the buffer does not have as much data as you asked to see). the buffer does not have as much data as you asked to see).
@param buffer the evbuffer to peek into, @param buffer the evbuffer to peek into,
@param len the number of bytes to try to peek. If negative, we @param len the number of bytes to try to peek. If len is negative, we
will try to fill as much of vec_out as we can. will try to fill as much of vec_out as we can. If len is negative
and vec_out is not provided, we return the number of evbuffer_iovecs
that would be needed to get all the data in the buffer.
@param start_at an evbuffer_ptr indicating the point at which we @param start_at an evbuffer_ptr indicating the point at which we
should start looking for data. NULL means, "At the start of the should start looking for data. NULL means, "At the start of the
buffer." buffer."

View File

@ -1780,6 +1780,10 @@ test_evbuffer_peek(void *info)
evbuffer_add_buffer(buf, tmp_buf); 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. */ /* Simple peek: get everything. */
i = evbuffer_peek(buf, -1, NULL, v, 20); i = evbuffer_peek(buf, -1, NULL, v, 20);
tt_int_op(i, ==, 16); /* we used only 16 chunks. */ tt_int_op(i, ==, 16); /* we used only 16 chunks. */