X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fapp-framework-binder.git;a=blobdiff_plain;f=src%2Fafb-wsj1.c;h=485099cd778f8608a7bd40a0dde05099b66c95c0;hp=73242e343b475818866eceae6246a35c50c48039;hb=65353dce81a629e042800bb7b86fcd869a76727e;hpb=a1a507793efff92b35603e4948e9f6dff4fba99c diff --git a/src/afb-wsj1.c b/src/afb-wsj1.c index 73242e34..485099cd 100644 --- a/src/afb-wsj1.c +++ b/src/afb-wsj1.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017, 2018 "IoT.bzh" + * Copyright (C) 2015-2020 "IoT.bzh" * Author: José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,6 +44,7 @@ static void wsj1_on_hangup(struct afb_wsj1 *wsj1); static void wsj1_on_text(struct afb_wsj1 *wsj1, char *text, size_t size); +static struct afb_wsj1_msg *wsj1_msg_make(struct afb_wsj1 *wsj1, char *text, size_t size); static struct afb_ws_itf wsj1_itf = { .on_hangup = (void*)wsj1_on_hangup, @@ -141,6 +142,32 @@ void afb_wsj1_unref(struct afb_wsj1 *wsj1) static void wsj1_on_hangup(struct afb_wsj1 *wsj1) { + struct wsj1_call *call, *ncall; + struct afb_wsj1_msg *msg; + char *text; + int len; + + static const char error_object_str[] = "{" + "\"jtype\":\"afb-reply\"," + "\"request\":{" + "\"status\":\"disconnected\"," + "\"info\":\"server hung up\"}}"; + + ncall = __atomic_exchange_n(&wsj1->calls, NULL, __ATOMIC_RELAXED); + while (ncall) { + call = ncall; + ncall = call->next; + len = asprintf(&text, "[%d,\"%s\",%s]", RETERR, call->id, error_object_str); + if (len > 0) { + msg = wsj1_msg_make(wsj1, text, (size_t)len); + if (msg != NULL) { + call->callback(call->closure, msg); + afb_wsj1_msg_unref(msg); + } + } + free(call); + } + if (wsj1->itf->on_hangup != NULL) wsj1->itf->on_hangup(wsj1->closure, wsj1); } @@ -280,11 +307,13 @@ static struct afb_wsj1_msg *wsj1_msg_make(struct afb_wsj1 *wsj1, char *text, siz /* scan */ n = wsj1_msg_scan(text, items); - if (n < 0) + if (n <= 0) goto bad_header; /* scans code: 2|3|4|5 */ - if (items[0][1] != 1) goto bad_header; + if (items[0][1] != 1) + goto bad_header; + switch (text[items[0][0]]) { case '2': msg->code = CALL; break; case '3': msg->code = RETOK; break;