ubusd: add another tx attempt on enqueueing the first message for a client
authorFelix Fietkau <nbd@nbd.name>
Tue, 1 Jul 2025 18:37:52 +0000 (20:37 +0200)
committerFelix Fietkau <nbd@nbd.name>
Tue, 1 Jul 2025 18:39:00 +0000 (20:39 +0200)
Make sure that the write buffer is indeed full before waiting for the uloop
event.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
ubusd.c
ubusd_main.c

diff --git a/ubusd.c b/ubusd.c
index 5aebce535cbf514625295d387e857a66382f0e5d..70ffffbaa37012fbe0aea140ea52e0d00aac2b85 100644 (file)
--- a/ubusd.c
+++ b/ubusd.c
@@ -161,12 +161,13 @@ static void ubus_msg_enqueue(struct ubus_client *cl, struct ubus_msg_buf *ub)
 /* takes the msgbuf reference */
 void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub)
 {
+       bool write_direct = list_empty(&cl->tx_queue);
        ssize_t written;
 
        if (ub->hdr.type != UBUS_MSG_MONITOR)
                ubusd_monitor_message(cl, ub, true);
 
-       if (list_empty(&cl->tx_queue)) {
+       if (write_direct) {
                written = ubus_msg_writev(cl->sock.fd, ub, 0);
 
                if (written < 0)
@@ -181,5 +182,9 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub)
                /* get an event once we can write to the socket again */
                uloop_fd_add(&cl->sock, ULOOP_READ | ULOOP_WRITE | ULOOP_EDGE_TRIGGER);
        }
+
        ubus_msg_enqueue(cl, ub);
+
+       if (write_direct)
+               cl->sock.cb(&cl->sock, ULOOP_WRITE);
 }
index 8422d6398ecce82124efff872eda06a079f3b045..0e4c6d8cd02a5c25fe992d9e0c055237c72bcee5 100644 (file)
@@ -101,7 +101,7 @@ retry_writev:
                cl->txq_ofs += written;
                cl->txq_len -= written;
                if (cl->txq_ofs < ub->len + sizeof(ub->hdr))
-                       break;
+                       goto retry_writev;
 
                cl->txq_ofs = 0;
                ubus_msg_list_free(ubl);