X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=libubus-req.c;h=db5061cad70887f15ab261154c51c732f2ea94ef;hp=ebc580684eb0f1e20fa197f96f5538010ca5e3c2;hb=6f4e11e1db399074273944329883f9c35e7daef6;hpb=3e45a782b22c067eab125b377474f5da11eabbe9 diff --git a/libubus-req.c b/libubus-req.c index ebc5806..db5061c 100644 --- a/libubus-req.c +++ b/libubus-req.c @@ -49,10 +49,9 @@ static void __ubus_process_req_data(struct ubus_request *req) } } -int __hidden ubus_start_request(struct ubus_context *ctx, struct ubus_request *req, +int __hidden __ubus_start_request(struct ubus_context *ctx, struct ubus_request *req, struct blob_attr *msg, int cmd, uint32_t peer) { - memset(req, 0, sizeof(*req)); if (msg && blob_pad_len(msg) > UBUS_MAX_MSGLEN) return -1; @@ -62,9 +61,21 @@ int __hidden ubus_start_request(struct ubus_context *ctx, struct ubus_request *r req->ctx = ctx; req->peer = peer; req->seq = ++ctx->request_seq; - return ubus_send_msg(ctx, req->seq, msg, cmd, peer, -1); + + return ubus_send_msg(ctx, req->seq, msg, cmd, peer, req->fd); +} + +int __hidden ubus_start_request(struct ubus_context *ctx, struct ubus_request *req, + struct blob_attr *msg, int cmd, uint32_t peer) +{ + memset(req, 0, sizeof(*req)); + + req->fd = -1; + + return __ubus_start_request(ctx, req, msg, cmd, peer); } + void ubus_abort_request(struct ubus_context *ctx, struct ubus_request *req) { if (list_empty(&req->list)) @@ -129,15 +140,9 @@ int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req, int req_timeout) { ubus_complete_handler_t complete_cb = req->complete_cb; - bool registered = ctx->sock.registered; int status = UBUS_STATUS_NO_DATA; int64_t timeout = 0, time_end = 0; - if (!registered) { - uloop_init(); - ubus_add_uloop(ctx); - } - if (req_timeout) time_end = get_time_msec() + req_timeout; @@ -153,12 +158,17 @@ int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req, timeout = time_end - get_time_msec(); if (timeout <= 0) { ubus_set_req_status(req, UBUS_STATUS_TIMEOUT); + uloop_cancelled = cancelled; break; } } ubus_poll_data(ctx, (unsigned int) timeout); uloop_cancelled = cancelled; + if (ctx->sock.eof) { + ubus_set_req_status(req, UBUS_STATUS_CONNECTION_FAILED); + break; + } } ctx->stack_depth--; if (ctx->stack_depth) @@ -171,12 +181,8 @@ int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req, if (req->complete_cb) req->complete_cb(req, status); - if (!registered) { - uloop_fd_delete(&ctx->sock); - - if (ctx->stack_depth) - ctx->pending_timer.cb(&ctx->pending_timer); - } + if (!ctx->stack_depth && !ctx->sock.registered) + ctx->pending_timer.cb(&ctx->pending_timer); return status; } @@ -204,8 +210,9 @@ int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req, return 0; } -int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method, - struct blob_attr *msg, struct ubus_request *req) +int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj, + const char *method, struct blob_attr *msg, + struct ubus_request *req, int fd) { blob_buf_init(&b, 0); blob_put_int32(&b, UBUS_ATTR_OBJID, obj); @@ -213,20 +220,21 @@ int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method if (msg) blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg)); - if (ubus_start_request(ctx, req, b.head, UBUS_MSG_INVOKE, obj) < 0) + memset(req, 0, sizeof(*req)); + req->fd = fd; + if (__ubus_start_request(ctx, req, b.head, UBUS_MSG_INVOKE, obj) < 0) return UBUS_STATUS_INVALID_ARGUMENT; - return 0; } -int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method, - struct blob_attr *msg, ubus_data_handler_t cb, void *priv, - int timeout) +int ubus_invoke_fd(struct ubus_context *ctx, uint32_t obj, const char *method, + struct blob_attr *msg, ubus_data_handler_t cb, void *priv, + int timeout, int fd) { struct ubus_request req; int rc; - rc = ubus_invoke_async(ctx, obj, method, msg, &req); + rc = ubus_invoke_async_fd(ctx, obj, method, msg, &req, fd); if (rc) return rc; @@ -465,3 +473,9 @@ void __hidden ubus_process_req_msg(struct ubus_context *ctx, struct ubus_msghdr_ break; } } + +int __ubus_monitor(struct ubus_context *ctx, const char *type) +{ + blob_buf_init(&b, 0); + return ubus_invoke(ctx, UBUS_SYSTEM_OBJECT_MONITOR, type, b.head, NULL, NULL, 1000); +}