fix message buffering
[project/ubus.git] / listener.c
index 188cda8..f05506a 100644 (file)
@@ -20,8 +20,12 @@ static int test_hello(struct ubus_context *ctx, struct ubus_object *obj,
                      struct ubus_request_data *req, const char *method,
                      struct blob_attr *msg)
 {
+       char *strbuf;
+
        blob_buf_init(&b, 0);
-       blobmsg_add_string(&b, "message", "Hello, world!\n");
+       strbuf = blobmsg_alloc_string_buffer(&b, "message", 64 + strlen(obj->name));
+       sprintf(strbuf, "%s: Hello, world\n", obj->name);
+       blobmsg_add_string_buffer(&b);
        ubus_send_reply(ctx, req, b.head);
        return 0;
 }
@@ -74,7 +78,7 @@ int main(int argc, char **argv)
                fprintf(stderr, "Object Type ID: %08x\n", test_object2.type->id);
        }
        uloop_init();
-       uloop_fd_add(&ctx->sock, ULOOP_READ | ULOOP_EDGE_TRIGGER);
+       ubus_add_uloop(ctx);
        uloop_run();
 
        ubus_free(ctx);