diff mbox

[OpenWrt-Devel,RFC] libubus.h: add ubus_connected function

Message ID 1453366733-6849-1-git-send-email-ben@benjii.net
State Changes Requested
Delegated to: Felix Fietkau
Headers show

Commit Message

Ben Kelly Jan. 21, 2016, 8:58 a.m. UTC
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 <ben@benjii.net>
---
 libubus.h | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox

Patch

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);