diff options
author | José Bollo <jose.bollo@iot.bzh> | 2018-08-21 21:15:31 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2018-08-23 10:18:18 +0200 |
commit | 2991a2564bc5e21b04dcb3157ce38804080c0056 (patch) | |
tree | 529563afe088e7a9d91383e2cc256d97bd4c0022 /src/afb-api-ws.c | |
parent | 7b6940f1524cac6172e71529a989424ff18fb850 (diff) |
afb-stub-ws: Add reconnection of ws-clients on need
This implementation detects deconnections and try to reconnect
lazily on need.
Bug-AGL: SPEC-1668
Change-Id: Ib2a20a4578f2da80afe1564c42de96c4aa250e64
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-api-ws.c')
-rw-r--r-- | src/afb-api-ws.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/afb-api-ws.c b/src/afb-api-ws.c index 6d8506c1..8069da22 100644 --- a/src/afb-api-ws.c +++ b/src/afb-api-ws.c @@ -50,6 +50,12 @@ struct api_ws_server /*** C L I E N T ***/ /******************************************************************************/ +static struct fdev *reopen_client(void *closure) +{ + const char *uri = closure; + return afb_socket_open_fdev(uri, 0); +} + int afb_api_ws_add_client(const char *uri, struct afb_apiset *declare_set, struct afb_apiset *call_set, int strong) { struct afb_stub_ws *stubws; @@ -73,8 +79,16 @@ int afb_api_ws_add_client(const char *uri, struct afb_apiset *declare_set, struc ERROR("can't setup client ws service to %s", uri); fdev_unref(fdev); } else { - if (afb_stub_ws_client_add(stubws, declare_set) >= 0) + if (afb_stub_ws_client_add(stubws, declare_set) >= 0) { +#if 1 + /* it is asserted here that uri is never released */ + afb_stub_ws_client_robustify(stubws, reopen_client, (void*)uri, NULL); +#else + /* it is asserted here that uri is released, so use a copy */ + afb_stub_ws_client_robustify(stubws, reopen_client, strdup(uri), free); +#endif return 0; + } ERROR("can't add the client to the apiset for service %s", uri); afb_stub_ws_unref(stubws); } |