From: Felix Fietkau Date: Tue, 1 Jul 2025 18:37:52 +0000 (+0200) Subject: ubusd: add another tx attempt on enqueueing the first message for a client X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=b1b783c7474269593b23ba01be8a86eb36e3471a;p=project%2Fubus.git ubusd: add another tx attempt on enqueueing the first message for a client Make sure that the write buffer is indeed full before waiting for the uloop event. Signed-off-by: Felix Fietkau --- diff --git a/ubusd.c b/ubusd.c index 5aebce5..70ffffb 100644 --- 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); } diff --git a/ubusd_main.c b/ubusd_main.c index 8422d63..0e4c6d8 100644 --- a/ubusd_main.c +++ b/ubusd_main.c @@ -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);