X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-api-ws.c;h=6b242e156db145f6b133517b9d1c389ffe01a7a4;hb=51ab7c2f95d6d459302423a57cc617021ef6126d;hp=8069da22bc3f67796cc8a8f94c4b240497335416;hpb=2991a2564bc5e21b04dcb3157ce38804080c0056;p=src%2Fapp-framework-binder.git diff --git a/src/afb-api-ws.c b/src/afb-api-ws.c index 8069da22..6b242e15 100644 --- a/src/afb-api-ws.c +++ b/src/afb-api-ws.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2018 "IoT.bzh" + * Copyright (C) 2015-2019 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -43,7 +43,7 @@ struct api_ws_server struct afb_apiset *apiset; /* the apiset for calling */ struct fdev *fdev; /* fdev handler */ uint16_t offapi; /* api name of the interface */ - char uri[1]; /* the uri of the server socket */ + char uri[]; /* the uri of the server socket */ }; /******************************************************************************/ @@ -130,7 +130,9 @@ static void api_ws_server_accept(struct api_ws_server *apiws) close(fd); } else { server = afb_stub_ws_create_server(fdev, &apiws->uri[apiws->offapi], apiws->apiset); - if (!server) + if (server) + afb_stub_ws_set_on_hangup(server, afb_stub_ws_unref); + else ERROR("can't serve accepted connection to %s: %m", apiws->uri); } } @@ -144,7 +146,7 @@ static void api_ws_server_listen_callback(void *closure, uint32_t revents, struc if ((revents & EPOLLIN) != 0) api_ws_server_accept(apiws); - if ((revents & EPOLLHUP) != 0) + else if ((revents & EPOLLHUP) != 0) api_ws_server_connect(apiws); } @@ -206,7 +208,7 @@ int afb_api_ws_add_server(const char *uri, struct afb_apiset *declare_set, struc /* make the structure */ lapi = strlen(api); extra = luri == (api - uri) + lapi ? 0 : lapi + 1; - apiws = malloc(sizeof * apiws + luri + extra); + apiws = malloc(sizeof * apiws + 1 + luri + extra); if (!apiws) { ERROR("out of memory"); errno = ENOMEM;