libubus: attempt to receive data before calling poll
authorFelix Fietkau <nbd@nbd.name>
Tue, 16 Apr 2019 09:00:49 +0000 (11:00 +0200)
committerFelix Fietkau <nbd@nbd.name>
Tue, 16 Apr 2019 09:02:53 +0000 (11:02 +0200)
Data is often already present here

Signed-off-by: Felix Fietkau <nbd@nbd.name>
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;