- if (conf->buffer_tree_given) {
- char *buf;
-
- if (btr_no_children(rn->btrn)) {
- t->error = -E_HTTP_RECV_NO_CHILD;
- goto err;
- }
- if (btr_bytes_pending(rn->btrn) > HTTP_RECV_MAX_PENDING) {
- t->error = -E_HTTP_RECV_OVERRUN;
- goto err;
- }
- buf = para_malloc(HTTP_RECV_READ_BUF_SIZE);
- t->error = recv_bin_buffer(phd->fd, buf, HTTP_RECV_READ_BUF_SIZE);
- if (t->error == 0)
- t->error = -E_RECV_EOF;
- if (t->error < 0) {
- free(buf);
- goto err;
- }
- btr_add_output(buf, t->error, rn->btrn);
- return;
- }
- t->error = -E_HTTP_RECV_OVERRUN;
- if (rn->loaded >= BUFSIZE)
- goto err;
- t->error = recv_bin_buffer(phd->fd, rn->buf + rn->loaded,
- BUFSIZE - rn->loaded);
- if (t->error == 0)
- t->error = -E_RECV_EOF;
- if (t->error < 0)
- goto err;
- rn->loaded += t->error;
- return;
-err:
- if (conf->buffer_tree_given) {
- btr_del_node(rn->btrn);
- rn->btrn = NULL;
+ ret = -E_HTTP_RECV_OVERRUN;
+ iovcnt = btr_pool_get_buffers(rn->btrp, iov);
+ if (iovcnt == 0)
+ goto out;
+ ret = readv_nonblock(rn->fd, iov, iovcnt, &s->rfds, &num_bytes);
+ if (num_bytes == 0)
+ goto out;
+ if (num_bytes <= iov[0].iov_len) /* only the first buffer was filled */
+ btr_add_output_pool(rn->btrp, num_bytes, btrn);
+ else { /* both buffers contain data */
+ btr_add_output_pool(rn->btrp, iov[0].iov_len, btrn);
+ btr_add_output_pool(rn->btrp, num_bytes - iov[0].iov_len, btrn);