dccp_recv/udp_recv: Use the new nonblock API.
[paraslash.git] / udp_recv.c
index 8dc8edc0a3c9588492a47a5d6389236c601dbdbd..5520c6fb65b29f9d12575b211cb990dd53e7d8d3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2009 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2010 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -67,40 +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);
-       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);