libubus: process pending messages in data handler if stack depth is 0
authorFelix Fietkau <nbd@nbd.name>
Thu, 12 Aug 2021 10:35:19 +0000 (12:35 +0200)
committerFelix Fietkau <nbd@nbd.name>
Wed, 8 Sep 2021 10:25:31 +0000 (12:25 +0200)
Process pending messages before attempting to read new ones. After completing
the poll, process any remaining pending messages.

A previous message processing call which issued a request from within
its handler may have left behind more object messages to process.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
libubus-io.c

index 3561ac462eb960fbbd828d9100d0656f101131cb..a1fb62b1162f5946ea182bfc78164ca813982eec 100644 (file)
@@ -314,12 +314,20 @@ void __hidden ubus_handle_data(struct uloop_fd *u, unsigned int events)
        struct ubus_context *ctx = container_of(u, struct ubus_context, sock);
        int recv_fd = -1;
 
-       while (get_next_msg(ctx, &recv_fd)) {
+       while (1) {
+               if (!ctx->stack_depth)
+                       ctx->pending_timer.cb(&ctx->pending_timer);
+
+               if (!get_next_msg(ctx, &recv_fd))
+                       break;
                ubus_process_msg(ctx, &ctx->msgbuf, recv_fd);
                if (uloop_cancelling() || ctx->cancel_poll)
                        break;
        }
 
+       if (!ctx->stack_depth)
+               ctx->pending_timer.cb(&ctx->pending_timer);
+
        if (u->eof)
                ctx->connection_lost(ctx);
 }