X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-proto-ws.c;h=86112a323eea2349f0b7740c06af7be116e72920;hb=7b6940f1524cac6172e71529a989424ff18fb850;hp=142afa98b5ed4a58ffae298ad3171bd82e5e29db;hpb=95ad0012182b5f32cc1dd9843304b58d263a7de0;p=src%2Fapp-framework-binder.git diff --git a/src/afb-proto-ws.c b/src/afb-proto-ws.c index 142afa98..86112a32 100644 --- a/src/afb-proto-ws.c +++ b/src/afb-proto-ws.c @@ -89,7 +89,7 @@ For the purpose of handling events the server can: struct client_call { struct client_call *next; /* the next call */ struct afb_proto_ws *protows; /* the proto_ws */ - void *request; + void *request; /* the request closure */ uint32_t callid; /* the message identifier */ }; @@ -261,10 +261,11 @@ static int readbuf_object(struct readbuf *rb, struct json_object **object) { const char *string; struct json_object *o; + enum json_tokener_error jerr; int rc = readbuf_string(rb, &string, NULL); if (rc) { - o = json_tokener_parse(string); - if (o == NULL && strcmp(string, "null")) + o = json_tokener_parse_verbose(string, &jerr); + if (jerr != json_tokener_success) o = json_object_new_string(string); *object = o; } @@ -935,8 +936,18 @@ static void on_hangup(void *closure) { struct afb_proto_ws *protows = closure; struct client_describe *cd, *ncd; + struct client_call *call, *ncall; + + ncd = __atomic_exchange_n(&protows->describes, NULL, __ATOMIC_RELAXED); + ncall = __atomic_exchange_n(&protows->calls, NULL, __ATOMIC_RELAXED); + + while (ncall) { + call= ncall; + ncall = call->next; + protows->client_itf->on_reply(protows->closure, call->request, NULL, "disconnected", "server hung up"); + free(call); + } - ncd = protows->describes; while (ncd) { cd= ncd; ncd = cd->next; @@ -1011,7 +1022,7 @@ struct afb_proto_ws *afb_proto_ws_create_server(struct fdev *fdev, const struct void afb_proto_ws_unref(struct afb_proto_ws *protows) { - if (!__atomic_sub_fetch(&protows->refcount, 1, __ATOMIC_RELAXED)) { + if (protows && !__atomic_sub_fetch(&protows->refcount, 1, __ATOMIC_RELAXED)) { afb_proto_ws_hangup(protows); afb_ws_destroy(protows->ws); pthread_mutex_destroy(&protows->mutex);