libubus: do not use uloop_run() inside ubus_complete_request
[project/ubus.git] / libubus-io.c
index bc054b8..9a6c7cd 100644 (file)
@@ -142,6 +142,9 @@ int __hidden ubus_send_msg(struct ubus_context *ctx, uint32_t seq,
        if (ret < 0)
                ctx->sock.eof = true;
 
+       if (fd >= 0)
+               close(fd);
+
        return ret;
 }
 
@@ -261,6 +264,17 @@ void __hidden ubus_handle_data(struct uloop_fd *u, unsigned int events)
                ctx->connection_lost(ctx);
 }
 
+void __hidden ubus_poll_data(struct ubus_context *ctx, int timeout)
+{
+       struct pollfd pfd = {
+               .fd = ctx->sock.fd,
+               .events = POLLIN | POLLERR,
+       };
+
+       poll(&pfd, 1, timeout);
+       ubus_handle_data(&ctx->sock, ULOOP_READ);
+}
+
 static void
 ubus_refresh_state(struct ubus_context *ctx)
 {