- /* configure the socket */
- if (fd >= 0) {
- fcntl(fd, F_SETFD, FD_CLOEXEC);
- fcntl(fd, F_SETFL, O_NONBLOCK);
- }
- return fd;
-}
-
-static struct fdev *api_ws_socket_fdev(const char *path, int server)
-{
- int fd;
- struct fdev *fdev;
-
- fd = api_ws_socket(path, server);
- if (fd < 0)
- fdev = 0;
- else {
- fdev = afb_fdev_create(fd);
- if (!fdev)
- close(fd);
- }
- if (!fdev)
- ERROR("can't make %s socket for %s", server ? "server" : "client", path);
- return fdev;
-}
-
-/**********************************************************************************/
-
-int afb_api_ws_add_client(const char *path, struct afb_apiset *declare_set, struct afb_apiset *call_set, int strong)
-{
- struct api_ws *apiws;
- struct afb_stub_ws *stubws;
-
- /* create the ws client api */
- apiws = api_ws_make(path);
- if (apiws == NULL)
- goto error;
-
- /* connect to the service */
- apiws->fdev = api_ws_socket_fdev(apiws->path, 0);
- if (!apiws->fdev)
- goto error2;
-
- stubws = afb_stub_ws_create_client(apiws->fdev, apiws->api, call_set);
- if (!stubws) {
- ERROR("can't setup client ws service to %s", apiws->path);
- goto error3;
- }
- if (afb_stub_ws_client_add(stubws, declare_set) < 0) {
- ERROR("can't add the client to the apiset for service %s", apiws->path);
- goto error3;
- }
- free(apiws);
- return 0;
-error3:
- afb_stub_ws_unref(stubws);
-error2:
- free(apiws);