- int ret;
-
- if (btrn) {
- ret = btr_node_status(btrn, 0, BTR_NT_ROOT);
- if (ret < 0)
- goto err;
- if (ret == 0)
- return;
- } else {
- if (rn->output_error && *rn->output_error < 0) {
- t->error = *rn->output_error;
- return;
- }
- }
- if (!FD_ISSET(pdd->fd, &s->rfds))
- return; /* nothing to do */
- if (rn->loaded >= DCCP_BUFSIZE) {
- t->error = -E_DCCP_OVERRUN;
- return;
- }
- if (btrn) {
- char *buf;
- size_t sz;
-
- sz = btr_pool_get_buffer(pdd->btrp, &buf);
- ret = -E_DCCP_OVERRUN;
- if (sz == 0)
- goto err;
- //buf = para_malloc(HTTP_RECV_READ_BUF_SIZE);
- //sz = HTTP_RECV_READ_BUF_SIZE;
- ret = recv_bin_buffer(pdd->fd, buf, sz);
- if (ret == 0)
- ret = -E_RECV_EOF;
- if (ret < 0)
- goto err;
- btr_add_output_pool(pdd->btrp, ret, btrn);
- return;
- }
- t->error = recv_bin_buffer(pdd->fd, rn->buf + rn->loaded,
- DCCP_BUFSIZE - rn->loaded);
- if (t->error > 0) {
- rn->loaded += t->error;
- return;
+ struct iovec iov[2];
+ int ret, iovcnt;
+ size_t num_bytes;
+
+ ret = task_get_notification(t);
+ if (ret < 0)
+ goto out;
+ ret = btr_node_status(btrn, 0, BTR_NT_ROOT);
+ if (ret <= 0)
+ goto out;
+ iovcnt = btr_pool_get_buffers(rn->btrp, iov);
+ ret = -E_DCCP_OVERRUN;
+ 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);