Admittedly, the semantic is a bit different, in the sense
that there are no progressive retry timeouts.

ubus_auto_connect() uses 1 second fixed retry intervals.
Whereas the old logic would start at 50 millisecs and
progress up to 1 second.

Other than that, the rest should be the same overall logic.
This should cleanup the code a bit.

For reference, the `ubus_add_uloop()` call is handled
by ubus_auto_connect() as well.

Signed-off-by: Alexandru Ardelean <ardeleana...@gmail.com>
---
 ubus.c | 55 +++++--------------------------------------------------
 1 file changed, 5 insertions(+), 50 deletions(-)

diff --git a/ubus.c b/ubus.c
index 8d521ac..5dd5452 100644
--- a/ubus.c
+++ b/ubus.c
@@ -20,68 +20,23 @@
 #include "procd.h"
 
 char *ubus_socket = NULL;
-static struct ubus_context *ctx;
-static struct uloop_timeout ubus_timer;
-static int timeout;
-
-static void reset_timeout(void)
-{
-       timeout = 50;
-}
-
-static void timeout_retry(void)
-{
-       uloop_timeout_set(&ubus_timer, timeout);
-       timeout *= 2;
-       if (timeout > 1000)
-               timeout = 1000;
-}
+static struct ubus_auto_conn conn;
 
 static void
-ubus_reconnect_cb(struct uloop_timeout *timeout)
+ubus_auto_connect_cb(struct ubus_context *ctx)
 {
-       if (!ubus_reconnect(ctx, ubus_socket)) {
-               ubus_add_uloop(ctx);
-               return;
-       }
-
-       timeout_retry();
-}
-
-static void
-ubus_disconnect_cb(struct ubus_context *ctx)
-{
-       ubus_timer.cb = ubus_reconnect_cb;
-       reset_timeout();
-       timeout_retry();
-}
-
-static void
-ubus_connect_cb(struct uloop_timeout *timeout)
-{
-       ctx = ubus_connect(ubus_socket);
-
-       if (!ctx) {
-               DEBUG(4, "Connection to ubus failed\n");
-               timeout_retry();
-               return;
-       }
-
-       ctx->connection_lost = ubus_disconnect_cb;
        ubus_init_service(ctx);
        ubus_init_system(ctx);
        watch_ubus(ctx);
 
        DEBUG(2, "Connected to ubus, id=%08x\n", ctx->local_id);
-       reset_timeout();
-       ubus_add_uloop(ctx);
        procd_state_ubus_connect();
 }
 
 void
 procd_connect_ubus(void)
 {
-       ubus_timer.cb = ubus_connect_cb;
-       reset_timeout();
-       timeout_retry();
+       conn.path = ubus_socket;
+       conn.cb = ubus_auto_connect_cb;
+       ubus_auto_connect(&conn);
 }
-- 
2.7.4


_______________________________________________
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev

Reply via email to