size_t out_total_len = outbuf->total_len;
size_t in_total_len = inbuf->total_len;
- if (in_total_len == 0)
+ if (in_total_len == 0 || outbuf == inbuf)
return (0);
if (out_total_len == 0) {
size_t out_total_len = outbuf->total_len;
size_t in_total_len = inbuf->total_len;
- if (!in_total_len)
+ if (!in_total_len || inbuf == outbuf)
return;
if (out_total_len == 0) {
int
evbuffer_remove(struct evbuffer *buf, void *data_out, size_t datlen)
{
+ /*XXX fails badly on sendfile case. */
struct evbuffer_chain *chain = buf->first, *tmp;
char *data = data_out;
size_t nread;
evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst,
size_t datlen)
{
+ /*XXX We should have an option to force this to be zero-copy.*/
+
+ /*XXX can fail badly on sendfile case. */
struct evbuffer_chain *chain = src->first;
struct evbuffer_chain *previous = chain, *previous_to_previous = NULL;
size_t nread = 0;
+ if (datlen == 0 || dst == src)
+ return (0);
+
/* short-cut if there is no more data buffered */
if (datlen >= src->total_len) {
datlen = src->total_len;
return (datlen);
}
- if (datlen == 0)
- return (0);
-
/* removes chains if possible */
while (chain->off <= datlen) {
nread += chain->off;