projects
/
project
/
ubus.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c55408c
)
add a callback for handling lost ubus connections
author
Felix Fietkau
<nbd@openwrt.org>
Mon, 31 Jan 2011 15:15:55 +0000
(16:15 +0100)
committer
Felix Fietkau
<nbd@openwrt.org>
Mon, 31 Jan 2011 15:15:55 +0000
(16:15 +0100)
libubus.c
patch
|
blob
|
history
libubus.h
patch
|
blob
|
history
diff --git
a/libubus.c
b/libubus.c
index
d90dc1f
..
64190f7
100644
(file)
--- a/
libubus.c
+++ b/
libubus.c
@@
-275,12
+275,16
@@
static void ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hd
ubus_parse_msg(hdr->data);
ubus_parse_msg(hdr->data);
- if (!attrbuf[UBUS_ATTR_METHOD] || !attrbuf[UBUS_ATTR_OBJID]) {
+ if (!attrbuf[UBUS_ATTR_OBJID])
+ return;
+
+ objid = blob_get_int32(attrbuf[UBUS_ATTR_OBJID]);
+
+ if (!attrbuf[UBUS_ATTR_METHOD]) {
ret = UBUS_STATUS_INVALID_ARGUMENT;
goto send;
}
ret = UBUS_STATUS_INVALID_ARGUMENT;
goto send;
}
- objid = blob_get_int32(attrbuf[UBUS_ATTR_OBJID]);
obj = avl_find_element(&ctx->objects, &objid, obj, avl);
if (!obj) {
ret = UBUS_STATUS_NOT_FOUND;
obj = avl_find_element(&ctx->objects, &objid, obj, avl);
if (!obj) {
ret = UBUS_STATUS_NOT_FOUND;
@@
-363,6
+367,9
@@
static void ubus_handle_data(struct uloop_fd *u, unsigned int events)
while (get_next_msg(ctx, false))
ubus_process_msg(ctx, hdr);
while (get_next_msg(ctx, false))
ubus_process_msg(ctx, hdr);
+
+ if (u->eof)
+ ctx->connection_lost(ctx);
}
int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req)
}
int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req)
@@
-528,6
+535,12
@@
int ubus_publish(struct ubus_context *ctx, struct ubus_object *obj)
return 0;
}
return 0;
}
+void ubus_default_connection_lost(struct ubus_context *ctx)
+{
+ if (ctx->sock.registered)
+ uloop_end();
+}
+
struct ubus_context *ubus_connect(const char *path)
{
struct ubus_context *ctx;
struct ubus_context *ubus_connect(const char *path)
{
struct ubus_context *ctx;
@@
-579,6
+592,8
@@
struct ubus_context *ubus_connect(const char *path)
ctx->local_id = hdr.hdr.peer;
free(buf);
ctx->local_id = hdr.hdr.peer;
free(buf);
+ ctx->connection_lost = ubus_default_connection_lost;
+
INIT_LIST_HEAD(&ctx->requests);
avl_init(&ctx->objects, ubus_cmp_id, false, NULL);
INIT_LIST_HEAD(&ctx->requests);
avl_init(&ctx->objects, ubus_cmp_id, false, NULL);
diff --git
a/libubus.h
b/libubus.h
index
2662878
..
b741e65
100644
(file)
--- a/
libubus.h
+++ b/
libubus.h
@@
-79,6
+79,8
@@
struct ubus_context {
uint32_t local_id;
uint32_t request_seq;
uint32_t local_id;
uint32_t request_seq;
+ void (*connection_lost)(struct ubus_context *ctx);
+
struct {
struct ubus_msghdr hdr;
char data[UBUS_MAX_MSGLEN - sizeof(struct ubus_msghdr)];
struct {
struct ubus_msghdr hdr;
char data[UBUS_MAX_MSGLEN - sizeof(struct ubus_msghdr)];