libubus: attempt to receive data before calling poll
[project/ubus.git] / libubus-io.c
index 887e88c1b48b30a7c0a8d456dd022059c8aace2e..228af5ca279c6d5f3d428c7ee4fe0b2670a68c1d 100644 (file)
@@ -174,9 +174,6 @@ static int recv_retry(struct ubus_context *ctx, struct iovec *iov, bool wait, in
        };
 
        while (iov->iov_len > 0) {
-               if (wait)
-                       wait_data(fd, false);
-
                if (recv_fd) {
                        msghdr.msg_control = &fd_buf;
                        msghdr.msg_controllen = sizeof(fd_buf);
@@ -210,6 +207,9 @@ static int recv_retry(struct ubus_context *ctx, struct iovec *iov, bool wait, in
                iov->iov_len -= bytes;
                iov->iov_base += bytes;
                total += bytes;
+
+               if (iov->iov_len > 0)
+                       wait_data(fd, false);
        }
 
        return total;