/*
- * Copyright (C) 2016, 2017 "IoT.bzh"
+ * Copyright (C) 2016, 2017, 2018 "IoT.bzh"
* Author: José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
#include <fcntl.h>
#include "afb-wsj1.h"
+#include "fdev-systemd.h"
/**************** WebSocket handshake ****************************/
const char *path;
struct addrinfo hint, *rai, *iai;
struct afb_wsj1 *result;
+ struct fdev *fdev;
/* scan the uri */
rc = parse_uri(uri, &host, &service, &path);
if (rc == 0) {
rc = negociate(fd, proto_json1, path, xhost);
if (rc == 0) {
- result = afb_wsj1_create(eloop, fd, itf, closure);
- if (result != NULL) {
- fcntl(fd, F_SETFL, O_NONBLOCK);
- break;
+ fdev = fdev_systemd_create(eloop, fd);
+ if (fdev) {
+ result = afb_wsj1_create(fdev, itf, closure);
+ if (result != NULL) {
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+ break;
+ }
}
}
}
}
return fd;
}
+
/*
* Establish a websocket-like client connection to the API of 'uri' and if successful
- * instanciate a client afb_proto_ws websocket for this API using 'itf' and 'closure'.
+ * instantiate a client afb_proto_ws websocket for this API using 'itf' and 'closure'.
* (see afb_proto_ws_create_client).
* The systemd event loop 'eloop' is used to handle the websocket.
- * Returns NULL in case of failure with errno set appriately.
+ * Returns NULL in case of failure with errno set appropriately.
*/
struct afb_proto_ws *afb_ws_client_connect_api(struct sd_event *eloop, const char *uri, struct afb_proto_ws_client_itf *itf, void *closure)
{
int fd;
struct afb_proto_ws *pws;
+ struct fdev *fdev;
fd = get_socket(uri);
if (fd >= 0) {
- pws = afb_proto_ws_create_client(eloop, fd, itf, closure);
- if (pws)
- return pws;
+ fdev = fdev_systemd_create(eloop, fd);
+ if (fdev) {
+ pws = afb_proto_ws_create_client(fdev, itf, closure);
+ if (pws)
+ return pws;
+ }
close(fd);
}
return NULL;
}
-
-