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 */
};
{
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;
}
{
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;
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);