-static int api_ws_socket(const char *path, int server)
-{
- int fd, rc;
-
- /* check for systemd socket */
- if (0 == strncmp(path, "sd:", 3))
- fd = sd_fds_for(path + 3);
- else {
- /* check for unix socket */
- if (0 == strncmp(path, "unix:", 5))
- /* unix socket */
- fd = api_ws_socket_unix(path + 5, server);
- else
- /* inet socket */
- fd = api_ws_socket_inet(path, server);
-
- if (fd >= 0 && server) {
- rc = 1;
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &rc, sizeof rc);
- rc = listen(fd, 5);
- }
- }
- /* configure the socket */
- if (fd >= 0) {
- fcntl(fd, F_SETFD, FD_CLOEXEC);
- fcntl(fd, F_SETFL, O_NONBLOCK);
- }
- return fd;
-}
-
-/**********************************************************************************/
-
-int afb_api_ws_add_client(const char *path, struct afb_apiset *apiset)
-{
- 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->fd = api_ws_socket(apiws->path, 0);
- if (apiws->fd < 0) {
- ERROR("can't connect to ws service %s", apiws->path);
- goto error2;
- }
-
- stubws = afb_stub_ws_create_client(apiws->fd, apiws->api, apiset);
- if (!stubws) {
- ERROR("can't setup client ws service to %s", apiws->path);
- goto error3;
- }
- free(apiws);
- return 0;
-
-error3:
- close(apiws->fd);
-error2:
- free(apiws);
-error:
- return -1;
-}
-
-static int api_ws_server_accept_client(struct api_ws *apiws, int fd)
-{
- return -!afb_stub_ws_create_server(fd, apiws->api, apiws->apiset);
-}