Tweaks, fixups, and comments on evbuffer_add_iovec

This commit is contained in:
Nick Mathewson 2011-11-11 17:56:08 -05:00
parent aaec5aca01
commit 27b5398fe0
2 changed files with 8 additions and 2 deletions

View File

@ -603,11 +603,16 @@ evbuffer_add_iovec(struct evbuffer * buf, struct evbuffer_iovec * vec, int n_vec
to_alloc += vec[n].iov_len;
}
if (evbuffer_expand(buf, to_alloc) < 0) {
if (_evbuffer_expand_fast(buf, to_alloc, 2) < 0) {
goto done;
}
for (n = 0; n < n_vec; n++) {
/* XXX each 'add' call here does a bunch of setup that's
* obviated by _evbuffer_expand_fast, and some cleanup that we
* would like to do only once. Instead we should just extract
* the part of the code that's needed. */
if (evbuffer_add(buf, vec[n].iov_base, vec[n].iov_len) < 0) {
goto done;
}

View File

@ -1837,6 +1837,7 @@ test_evbuffer_add_iovec(void * ptr)
"On the one hand, it cuts for Justice, imposing practical morality upon those who fear it.",
"Conscience does not always adhere to rational judgment.",
"Guilt is always a self-imposed burden, but it is not always rightly imposed."
/* -- R.A. Salvatore, _Sojurn_ */
};
size_t expected_length = 0;
size_t returned_length = 0;
@ -1846,7 +1847,7 @@ test_evbuffer_add_iovec(void * ptr)
for (i = 0; i < 4; i++) {
vec[i].iov_len = strlen(data[i]);
vec[i].iov_base = data[i];
vec[i].iov_base = (char*) data[i];
expected_length += vec[i].iov_len;
}