diff --git a/arch/eventloop_posix_epoll.c b/arch/eventloop_posix_epoll.c index dfa99d4476b..fe25fd8a26e 100644 --- a/arch/eventloop_posix_epoll.c +++ b/arch/eventloop_posix_epoll.c @@ -103,6 +103,13 @@ UA_EventLoopPOSIX_pollFDs(UA_EventLoopPOSIX *el, UA_DateTime listenTimeout) { /* Process all received events */ for(int i = 0; i < events; i++) { UA_RegisteredFD *rfd = (UA_RegisteredFD*)epoll_events[i].data.ptr; + + /* The rfd is already registered for removal. Don't process incoming + * events any longer. */ + if(rfd->dc.callback) + continue; + + /* Get the event */ short revent = 0; if((epoll_events[i].events & EPOLLIN) == EPOLLIN) { revent = UA_FDEVENT_IN; @@ -111,6 +118,8 @@ UA_EventLoopPOSIX_pollFDs(UA_EventLoopPOSIX *el, UA_DateTime listenTimeout) { } else { revent = UA_FDEVENT_ERR; } + + /* Call the EventSource callback */ rfd->eventSourceCB(rfd->es, rfd, revent); } return UA_STATUSCODE_GOOD; diff --git a/arch/eventloop_posix_select.c b/arch/eventloop_posix_select.c index 16a6a54b886..992e02f597f 100644 --- a/arch/eventloop_posix_select.c +++ b/arch/eventloop_posix_select.c @@ -135,26 +135,32 @@ UA_EventLoopPOSIX_pollFDs(UA_EventLoopPOSIX *el, UA_DateTime listenTimeout) { } /* Loop over all registered FD to see if an event arrived. Yes, this is why - * select is slow for many open sockets. */ + * select is slow for many open sockets. */ for(size_t i = 0; i < el->fdsSize; i++) { UA_RegisteredFD *rfd = el->fds[i]; - UA_FD fd = rfd->fd; - /* Error Event */ + /* The rfd is already registered for removal. Don't process incoming + * events any longer. */ + if(rfd->dc.callback) + continue; + + /* Event signaled for the fd? */ short event = 0; - if(FD_ISSET(fd, &readset)) { + if(FD_ISSET(rfd->fd, &readset)) { event = UA_FDEVENT_IN; - } else if(FD_ISSET(fd, &writeset)) { + } else if(FD_ISSET(rfd->fd, &writeset)) { event = UA_FDEVENT_OUT; - } else if(FD_ISSET(fd, &errset)) { + } else if(FD_ISSET(rfd->fd, &errset)) { event = UA_FDEVENT_ERR; } else { continue; } UA_LOG_DEBUG(el->eventLoop.logger, UA_LOGCATEGORY_EVENTLOOP, - "Processing event %u on fd %u", (unsigned)event, (unsigned)fd); + "Processing event %u on fd %u", (unsigned)event, + (unsigned)rfd->fd); + /* Call the EventSource callback */ rfd->eventSourceCB(rfd->es, rfd, event); /* The fd has removed itself */