ubusd: convert tx_queue to linked list
[project/ubus.git] / ubusd.c
diff --git a/ubusd.c b/ubusd.c
index 5993653785e01cf6767d6d3f5a50e86e33ec660d..c324c704a74f7494407f1240f3a8ccfbc2f084cb 100644 (file)
--- a/ubusd.c
+++ b/ubusd.c
@@ -133,13 +133,25 @@ ssize_t ubus_msg_writev(int fd, struct ubus_msg_buf *ub, size_t offset)
        return ret;
 }
 
+void ubus_msg_list_free(struct ubus_msg_buf_list *ubl)
+{
+       list_del_init(&ubl->list);
+       ubus_msg_free(ubl->msg);
+       free(ubl);
+}
+
 static void ubus_msg_enqueue(struct ubus_client *cl, struct ubus_msg_buf *ub)
 {
-       if (cl->tx_queue[cl->txq_tail])
+       struct ubus_msg_buf_list *ubl;
+
+       ubl = calloc(1, sizeof(struct ubus_msg_buf_list));
+       if (!ubl)
                return;
 
-       cl->tx_queue[cl->txq_tail] = ubus_msg_ref(ub);
-       cl->txq_tail = (cl->txq_tail + 1) % ARRAY_SIZE(cl->tx_queue);
+       INIT_LIST_HEAD(&ubl->list);
+       ubl->msg = ubus_msg_ref(ub);
+
+       list_add_tail(&cl->tx_queue, &ubl->list);
 }
 
 /* takes the msgbuf reference */
@@ -150,7 +162,7 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub)
        if (ub->hdr.type != UBUS_MSG_MONITOR)
                ubusd_monitor_message(cl, ub, true);
 
-       if (!cl->tx_queue[cl->txq_cur]) {
+       if (list_empty(&cl->tx_queue)) {
                written = ubus_msg_writev(cl->sock.fd, ub, 0);
 
                if (written < 0)