From c7f1fd1a0b14686d06043be27f0ac03265aac16f Mon Sep 17 00:00:00 2001 From: Guerra Mattia Date: Thu, 28 Sep 2017 15:09:56 +0200 Subject: AMUtil: fix missed copy in list Poll When copying the list of Poll fd, also the revents have to be copied. This is very important for AM Plugins which rely on revents in order to consume data. Without updating the revents, there's concrete risk of endless poll and general stuck situation. Signed-off-by: Guerra Mattia --- AudioManagerUtilities/src/CAmSocketHandler.cpp | 31 +++++++++++++++----------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/AudioManagerUtilities/src/CAmSocketHandler.cpp b/AudioManagerUtilities/src/CAmSocketHandler.cpp index 7b0fc5d..fad60e5 100644 --- a/AudioManagerUtilities/src/CAmSocketHandler.cpp +++ b/AudioManagerUtilities/src/CAmSocketHandler.cpp @@ -69,10 +69,13 @@ CAmSocketHandler::CAmSocketHandler() : short event = 0; sh_pollHandle_t handle; event |= POLLIN; - if (addFDPoll(mPipe[0], event, NULL, [](const pollfd pollfd, const sh_pollHandle_t, void*) - {}, [](const sh_pollHandle_t, void*) - { return (false);}, NULL, NULL, handle) != E_OK) + if (addFDPoll(mPipe[0], event, NULL, + [](const pollfd, const sh_pollHandle_t, void*){}, + [](const sh_pollHandle_t, void*) { return (false); }, + NULL, NULL, handle) != E_OK) + { mInternalCodes |= internal_codes_e::FD_ERROR; + } } CAmSocketHandler::~CAmSocketHandler() @@ -99,10 +102,8 @@ void CAmSocketHandler::start_listenting() #endif timespec buffertime; - std::list listPoll; VectorListPoll_t cloneListPoll; VectorListPoll_t::iterator listmPollIt; - VectorListPollfd_t::iterator itMfdPollingArray; VectorListPollfd_t fdPollingArray; //! listPoll; //todo: here could be a timer that makes sure naughty plugins return! - listPoll.clear(); //stage 0+1, call firedCB - for (itMfdPollingArray = fdPollingArray.begin(); itMfdPollingArray != fdPollingArray.end(); itMfdPollingArray++) + listmPollIt = cloneListPoll.begin(); + for (auto it : fdPollingArray) { - if (CAmSocketHandler::eventFired(*itMfdPollingArray)) - { - listmPollIt = cloneListPoll.begin(); - std::advance(listmPollIt, std::distance(fdPollingArray.begin(), itMfdPollingArray)); - + if (CAmSocketHandler::eventFired(it)) + { + listmPollIt->pollfdValue.revents = it.revents; listPoll.push_back(*listmPollIt); CAmSocketHandler::fire(*listmPollIt); } + else + { + listmPollIt->pollfdValue.revents = 0; + } + listmPollIt++; } //stage 2, lets ask around if some dispatching is necessary, the ones who need stay on the list @@ -395,7 +400,7 @@ am::am_Error_e CAmSocketHandler::addFDPoll(const int fd, const short event, IAmS { std::function prepareCB; //preperation callback - std::function firedCB; //fired callback + std::function firedCB; //fired callback std::function checkCB; //check callback std::function dispatchCB; //check callback -- cgit v1.2.1