X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-ws.c;h=d0cfc8a8bb0a10fe7f32415511fcd6164c756d35;hb=5dd6480727cc1ecb12483fc4d971d73176505748;hp=da248c895ceed7948a89eb932bfd14ef123be953;hpb=f262b0f726ac0577f40525038b779185f144873f;p=src%2Fapp-framework-binder.git 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 #include +#include + #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: