When using ubus_auto_connect it is useful to be able to determine the 
connection status of the ubus context. I'm testing the ctx.sock.registered flag 
here, though I'm not sure if this is the best way to go about this check. I'm 
happy for someone to tell me this is not the correct way to do this.

Cheers

Signed-off-by: Ben Kelly <b...@benjii.net>
---
 libubus.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libubus.h b/libubus.h
index 54e7d48..9824b65 100644
--- a/libubus.h
+++ b/libubus.h
@@ -234,6 +234,11 @@ int ubus_connect_ctx(struct ubus_context *ctx, const char 
*path);
 void ubus_auto_connect(struct ubus_auto_conn *conn);
 int ubus_reconnect(struct ubus_context *ctx, const char *path);
 
+static inline bool ubus_connected(struct ubus_context *ctx)
+{
+       return (ctx && ctx->sock.registered);
+}
+
 /* call this only for struct ubus_context pointers returned by ubus_connect() 
*/
 void ubus_free(struct ubus_context *ctx);
 
-- 
2.5.0
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to