X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-ws.c;h=1db9ad5445dd0417bb520b1fa0c611e9d32a408a;hb=65353dce81a629e042800bb7b86fcd869a76727e;hp=c48a5e242576e157bc4dd8883421d1fbeede2adc;hpb=0891ef4826e347d5554c630b5c0ce73c68f76c9c;p=src%2Fapp-framework-binder.git diff --git a/src/afb-ws.c b/src/afb-ws.c index c48a5e24..1db9ad54 100644 --- a/src/afb-ws.c +++ b/src/afb-ws.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 "IoT.bzh" + * Copyright (C) 2015-2020 "IoT.bzh" * Author: José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,12 +26,9 @@ #include #include -#include - #include "websock.h" #include "afb-ws.h" - -#include "afb-common.h" +#include "fdev.h" /* * declaration of the websock interface for afb-ws @@ -89,7 +86,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 */ - sd_event_source *evsrc; /* the event source for the socket */ + struct fdev *fdev; /* the fdev for the socket */ struct buf buffer; /* the last read fragment */ }; @@ -123,8 +120,8 @@ static void aws_disconnect(struct afb_ws *ws, int call_on_hangup) struct websock *wsi = ws->ws; if (wsi != NULL) { ws->ws = NULL; - sd_event_source_unref(ws->evsrc); - ws->evsrc = NULL; + fdev_set_callback(ws->fdev, NULL, 0); + fdev_unref(ws->fdev); websock_destroy(wsi); free(ws->buffer.buffer); ws->state = waiting; @@ -133,13 +130,12 @@ 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) +static void fdevcb(void *ws, uint32_t revents, struct fdev *fdev) { - if ((revents & EPOLLIN) != 0) - aws_on_readable(ws); if ((revents & EPOLLHUP) != 0) afb_ws_hangup(ws); - return 0; + else if ((revents & EPOLLIN) != 0) + aws_on_readable(ws); } /* @@ -151,12 +147,11 @@ static int io_event_callback(sd_event_source *src, int fd, uint32_t revents, voi * * Returns the handle for the afb_ws created or NULL on error. */ -struct afb_ws *afb_ws_create(struct sd_event *eloop, int fd, const struct afb_ws_itf *itf, void *closure) +struct afb_ws *afb_ws_create(struct fdev *fdev, const struct afb_ws_itf *itf, void *closure) { - int rc; struct afb_ws *result; - assert(fd >= 0); + assert(fdev); /* allocation */ result = malloc(sizeof * result); @@ -164,7 +159,8 @@ struct afb_ws *afb_ws_create(struct sd_event *eloop, int fd, const struct afb_ws goto error; /* init */ - result->fd = fd; + result->fdev = fdev; + result->fd = fdev_fd(fdev); result->state = waiting; result->itf = itf; result->closure = closure; @@ -176,19 +172,15 @@ struct afb_ws *afb_ws_create(struct sd_event *eloop, int fd, const struct afb_ws if (result->ws == NULL) goto error2; - /* creates the evsrc */ - rc = sd_event_add_io(eloop, &result->evsrc, result->fd, EPOLLIN, io_event_callback, result); - if (rc < 0) { - errno = -rc; - goto error3; - } + /* finalize */ + fdev_set_events(fdev, EPOLLIN); + fdev_set_callback(fdev, fdevcb, result); return result; -error3: - websock_destroy(result->ws); error2: free(result); error: + fdev_unref(fdev); return NULL; }