X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fprocd.git;a=blobdiff_plain;f=ubus.c;h=8d521acf11e3ef17c36e9865c6b0cc1056f97c7f;hp=6166254a9af8cba5a2438a907c0d776f6b5987fe;hb=8d720b2c2e569885c6e1e7eab68d36f31818ed84;hpb=916f95cb58604038695347ee41a430d8ca1f0556;ds=sidebyside diff --git a/ubus.c b/ubus.c index 6166254..8d521ac 100644 --- a/ubus.c +++ b/ubus.c @@ -22,21 +22,38 @@ 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 void ubus_reconnect_cb(struct uloop_timeout *timeout) { - if (!ubus_reconnect(ctx, ubus_socket)) + if (!ubus_reconnect(ctx, ubus_socket)) { ubus_add_uloop(ctx); - else - uloop_timeout_set(timeout, 2000); + return; + } + + timeout_retry(); } static void ubus_disconnect_cb(struct ubus_context *ctx) { ubus_timer.cb = ubus_reconnect_cb; - uloop_timeout_set(&ubus_timer, 2000); + reset_timeout(); + timeout_retry(); } static void @@ -46,21 +63,25 @@ ubus_connect_cb(struct uloop_timeout *timeout) if (!ctx) { DEBUG(4, "Connection to ubus failed\n"); - uloop_timeout_set(&ubus_timer, 1000); + 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; - uloop_timeout_set(&ubus_timer, 1000); + reset_timeout(); + timeout_retry(); }