struct btr_node *btrn = rn->btrn;
struct iovec iov[2];
int ret, iovcnt;
+ size_t num_bytes;
ret = btr_node_status(btrn, 0, BTR_NT_ROOT);
- if (ret < 0)
- goto err;
- if (ret == 0)
- return;
- if (!FD_ISSET(pdd->fd, &s->rfds))
- return; /* nothing to do */
+ if (ret <= 0)
+ goto out;
iovcnt = btr_pool_get_buffers(pdd->btrp, iov);
ret = -E_DCCP_OVERRUN;
if (iovcnt == 0)
- goto err;
- ret = para_readv(pdd->fd, iov, iovcnt);
- /* EAGAIN is possible even if FD_ISSET */
- if (ret < 0 && is_errno(-ret, EAGAIN))
- return;
- if (ret == 0)
- ret = -E_RECV_EOF;
- if (ret < 0)
- goto err;
- if (ret <= iov[0].iov_len) /* only the first buffer was filled */
- btr_add_output_pool(pdd->btrp, ret, btrn);
+ goto out;
+ ret = readv_nonblock(pdd->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(pdd->btrp, num_bytes, btrn);
else { /* both buffers contain data */
btr_add_output_pool(pdd->btrp, iov[0].iov_len, btrn);
- btr_add_output_pool(pdd->btrp, ret - iov[0].iov_len, btrn);
+ btr_add_output_pool(pdd->btrp, num_bytes - iov[0].iov_len, btrn);
}
- return;
-err:
+out:
+ if (ret >= 0)
+ return;
btr_remove_node(rn->btrn);
t->error = ret;
}
return readv_nonblock(fd, &iov, 1, rfds, num_bytes);
}
-/**
- * Simple wrapper for readv().
- *
- * \param fd The file descriptor to read from.
- * \param iov Scatter/gather array used in readv().
- * \param iovcnt Number of elements in \a iov.
- *
- * \return A negative error code on errors, the return value of the underlying
- * call to readv() otherwise.
- *
- * \sa readv(2).
- */
-int para_readv(int fd, struct iovec *iov, int iovcnt)
-{
- int ret = readv(fd, iov, iovcnt);
-
- if (ret < 0)
- return -ERRNO_TO_PARA_ERROR(errno);
- return ret;
-}
-
/**
* Check whether a file exists.
*
/** \file fd.h exported symbols from fd.c */
int write_all(int fd, const char *buf, size_t *len);
-int para_readv(int fd, struct iovec *iov, int iovcnt);
int file_exists(const char *);
int para_select(int n, fd_set *readfds, fd_set *writefds,
struct timeval *timeout_tv);
struct receiver_node *rn = container_of(t, struct receiver_node, task);
struct private_udp_recv_data *purd = rn->private_data;
struct btr_node *btrn = rn->btrn;
- size_t packet_size;
+ size_t num_bytes;
struct iovec iov[2];
- int ret, iovcnt;
+ int ret, readv_ret, iovcnt;
t->error = 0;
ret = btr_node_status(btrn, 0, BTR_NT_ROOT);
- if (ret < 0)
- goto err;
- if (ret == 0)
- return;
- if (!FD_ISSET(purd->fd, &s->rfds))
- return;
+ if (ret <= 0)
+ goto out;
iovcnt = btr_pool_get_buffers(purd->btrp, iov);
ret = -E_UDP_OVERRUN;
if (iovcnt == 0)
- goto err;
- ret = para_readv(purd->fd, iov, iovcnt);
- /* EAGAIN is possible even if FD_ISSET */
- if (ret < 0 && is_errno(-ret, EAGAIN))
- return;
- if (ret == 0)
- ret = -E_RECV_EOF;
+ goto out;
+ ret = readv_nonblock(purd->fd, iov, iovcnt, &s->rfds, &num_bytes);
+ if (num_bytes == 0)
+ goto out;
+ readv_ret = ret;
+ ret = udp_check_eof(num_bytes, iov);
if (ret < 0)
- goto err;
- packet_size = ret;
- ret = udp_check_eof(packet_size, iov);
- if (ret < 0)
- goto err;
- if (iov[0].iov_len >= packet_size)
- btr_add_output_pool(purd->btrp, packet_size, btrn);
+ goto out;
+ if (iov[0].iov_len >= num_bytes)
+ btr_add_output_pool(purd->btrp, num_bytes, btrn);
else { /* both buffers contain data */
btr_add_output_pool(purd->btrp, iov[0].iov_len, btrn);
- btr_add_output_pool(purd->btrp, packet_size - iov[0].iov_len,
+ btr_add_output_pool(purd->btrp, num_bytes - iov[0].iov_len,
btrn);
}
- return;
-err:
+ ret = readv_ret;
+out:
+ if (ret >= 0)
+ return;
btr_remove_node(btrn);
t->error = ret;
close(purd->fd);