]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
dccp_recv/udp_recv: Use the new nonblock API.
authorAndre Noll <maan@systemlinux.org>
Sun, 25 Apr 2010 17:34:35 +0000 (19:34 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 25 Apr 2010 17:34:35 +0000 (19:34 +0200)
This simplifies the code quite a bit. In particular it allows to
kill the extra check for EAGAIN that was necessary to deal with
unreliable return value of FD_ISSET().

dccp_recv.c
fd.c
fd.h
udp_recv.c

index f71a7253a0296e8c0f849147287b5cede93233e0..2ab9fcab0c16bea881d4a4f6fc2f099b27ef3037 100644 (file)
@@ -153,34 +153,27 @@ static void dccp_recv_post_select(struct sched *s, struct task *t)
        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;
 }
diff --git a/fd.c b/fd.c
index d56a31101ade30bd8790d8082f8a3be5f5b84004..2e59bc95111d4e94daac0cf070ddf48b0dde4c81 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -177,27 +177,6 @@ int read_nonblock(int fd, void *buf, size_t sz, fd_set *rfds, size_t *num_bytes)
        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.
  *
diff --git a/fd.h b/fd.h
index b95588207d4c69e303409184e7a91e52df643e00..787784d3ef50311728347aee68dbf5395aaab0c7 100644 (file)
--- a/fd.h
+++ b/fd.h
@@ -7,7 +7,6 @@
 /** \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);
index 00ad3e2781745c2e04af80dc462b75171e380dd0..5520c6fb65b29f9d12575b211cb990dd53e7d8d3 100644 (file)
@@ -67,43 +67,36 @@ static void udp_recv_post_select(__a_unused struct sched *s, struct task *t)
        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);