aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-ws.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-05-03 10:03:58 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-05-04 11:55:38 +0200
commit5dd6480727cc1ecb12483fc4d971d73176505748 (patch)
tree495925fdba144f609daaad6da07281fd9bd94b69 /src/afb-ws.c
parentf262b0f726ac0577f40525038b779185f144873f (diff)
Switch to libsystemd events
This patch removes part of code that are not specific in favour of a more shared library. Change-Id: I3506e7514181cfbed753559bb65460f95b2141c9 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-ws.c')
-rw-r--r--src/afb-ws.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/afb-ws.c b/src/afb-ws.c
index da248c89..d0cfc8a8 100644
--- a/src/afb-ws.c
+++ b/src/afb-ws.c
@@ -24,10 +24,12 @@
#include <sys/uio.h>
#include <string.h>
+#include <systemd/sd-event.h>
+
#include "websock.h"
#include "afb-ws.h"
-#include "utils-upoll.h"
+#include "afb-common.h"
/*
* declaration of the websock interface for afb-ws
@@ -85,7 +87,7 @@ struct afb_ws
const struct afb_ws_itf *itf; /* the callback interface */
void *closure; /* closure when calling the callbacks */
struct websock *ws; /* the websock handler */
- struct upoll *up; /* the upoll handler for the socket */
+ sd_event_source *evsrc; /* the event source for the socket */
struct buf buffer; /* the last read fragment */
};
@@ -109,8 +111,8 @@ static void aws_disconnect(struct afb_ws *ws, int call_on_hangup)
struct websock *wsi = ws->ws;
if (wsi != NULL) {
ws->ws = NULL;
- upoll_close(ws->up);
- ws->up = NULL;
+ sd_event_source_unref(ws->evsrc);
+ ws->evsrc = NULL;
websock_destroy(wsi);
free(aws_pick_buffer(ws).buffer);
ws->state = waiting;
@@ -119,6 +121,15 @@ static void aws_disconnect(struct afb_ws *ws, int call_on_hangup)
}
}
+static int io_event_callback(sd_event_source *src, int fd, uint32_t revents, void *ws)
+{
+ if ((revents & EPOLLIN) != 0)
+ aws_on_readable(ws);
+ if ((revents & EPOLLHUP) != 0)
+ afb_ws_hangup(ws);
+ return 0;
+}
+
/*
* Creates the afb_ws structure for the file descritor
* 'fd' and the callbacks described by the interface 'itf'
@@ -128,6 +139,7 @@ static void aws_disconnect(struct afb_ws *ws, int call_on_hangup)
*/
struct afb_ws *afb_ws_create(int fd, const struct afb_ws_itf *itf, void *closure)
{
+ int rc;
struct afb_ws *result;
assert(fd >= 0);
@@ -150,15 +162,12 @@ struct afb_ws *afb_ws_create(int fd, const struct afb_ws_itf *itf, void *closure
if (result->ws == NULL)
goto error2;
- /* creates the upoll */
- result->up = upoll_open(result->fd, result);
- if (result->up == NULL)
+ /* creates the evsrc */
+ rc = sd_event_add_io(afb_common_get_event_loop(), &result->evsrc, result->fd, EPOLLIN, io_event_callback, result);
+ if (rc < 0) {
+ errno = -rc;
goto error3;
-
- /* init the upoll */
- upoll_on_readable(result->up, (void*)aws_on_readable);
- upoll_on_hangup(result->up, (void*)afb_ws_hangup);
-
+ }
return result;
error3: