/*
- * Copyright (C) 2015-2018 "IoT.bzh"
+ * Copyright (C) 2015-2020 "IoT.bzh"
* Author José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
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 */
};
/******************************************************************************/
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);
}
}
{
struct api_ws_server *apiws = closure;
- if ((revents & EPOLLIN) != 0)
- api_ws_server_accept(apiws);
if ((revents & EPOLLHUP) != 0)
api_ws_server_connect(apiws);
+ else if ((revents & EPOLLIN) != 0)
+ api_ws_server_accept(apiws);
}
static void api_ws_server_disconnect(struct api_ws_server *apiws)
/* 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;