Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ubus: add explicit support for deferring incoming requests #195

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/ubus.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ typedef struct {
struct uloop_timeout timeout;
struct ubus_context *ctx;
size_t registry_index;
bool deferred;
bool replied;
uc_vm_t *vm;
} uc_ubus_request_t;
Expand Down Expand Up @@ -845,6 +846,18 @@ uc_ubus_request_reply(uc_vm_t *vm, size_t nargs)
ok_return(ucv_boolean_new(true));
}

static uc_value_t *
uc_ubus_request_defer(uc_vm_t *vm, size_t nargs)
{
uc_ubus_request_t *callctx = uc_fn_thisval("ubus.request");

if (!callctx)
return NULL;

callctx->deferred = true;
return ucv_boolean_new(true);
}

static uc_value_t *
uc_ubus_request_error(uc_vm_t *vm, size_t nargs)
{
Expand Down Expand Up @@ -1256,7 +1269,7 @@ uc_ubus_handle_reply_common(struct ubus_context *ctx,
/* If neither a deferred ubus request, nor a plain object were
* returned and if reqobj.reply() hasn't been called, immediately
* finish deferred request with UBUS_STATUS_NO_DATA. */
else if (!callctx->replied) {
else if (!callctx->replied && !callctx->deferred) {
rv = UBUS_STATUS_NO_DATA;

if (ucv_type(res) == UC_INTEGER) {
Expand Down Expand Up @@ -2003,6 +2016,7 @@ static const uc_function_list_t object_fns[] = {
static const uc_function_list_t request_fns[] = {
{ "reply", uc_ubus_request_reply },
{ "error", uc_ubus_request_error },
{ "defer", uc_ubus_request_defer },
};

static const uc_function_list_t notify_fns[] = {
Expand Down Expand Up @@ -2058,6 +2072,7 @@ static void free_object(void *ud) {
static void free_request(void *ud) {
uc_ubus_request_t *callctx = ud;

uc_ubus_request_finish(callctx, UBUS_STATUS_TIMEOUT, NULL);
uloop_timeout_cancel(&callctx->timeout);
free(callctx);
}
Expand Down
Loading