summaryrefslogtreecommitdiff
path: root/AudioManagerUtilities/src/CAmSocketHandler.cpp
diff options
context:
space:
mode:
authorJens Lorenz <jlorenz@de.adit-jv.com>2018-03-29 16:11:34 +0200
committerJens Lorenz <jlorenz@de.adit-jv.com>2018-04-09 17:04:42 +0200
commitfff370c2d89acfed702b7c615650706c3c1fadd2 (patch)
tree37852d4dcccb3ea5a2a2b01b3da25a7b3d3d691c /AudioManagerUtilities/src/CAmSocketHandler.cpp
parentb487c9b8c5e18797e91a77a4a0b447d63a2a42da (diff)
downloadaudiomanager-fff370c2d89acfed702b7c615650706c3c1fadd2.tar.gz
AMUtil: Fix startup sequence addFdPoll and removeFdPoll
In case plugins add new fdpoll elements and directly removing them afterwards the state inside the structure will be changed to REMOVE. REMOVE will lead all the time to an erase which will not work in case the pointer is at .end() of vector or the element itself is not the correct one. Both cases will be fixed just by checking if the fd is the same. Signed-off-by: Jens Lorenz <jlorenz@de.adit-jv.com>
Diffstat (limited to 'AudioManagerUtilities/src/CAmSocketHandler.cpp')
-rw-r--r--AudioManagerUtilities/src/CAmSocketHandler.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/AudioManagerUtilities/src/CAmSocketHandler.cpp b/AudioManagerUtilities/src/CAmSocketHandler.cpp
index 1e7db6a..e5752b4 100644
--- a/AudioManagerUtilities/src/CAmSocketHandler.cpp
+++ b/AudioManagerUtilities/src/CAmSocketHandler.cpp
@@ -40,9 +40,9 @@
#include <sys/timerfd.h>
#endif
+#define END_EVENT (UINT64_MAX >> 1)
#define SHPOLL_IS_ACTIVE(state) (!(state == poll_states_e::REMOVE || state == poll_states_e::CLOSE))
-
namespace am
{
@@ -72,7 +72,7 @@ CAmSocketHandler::CAmSocketHandler() :
ssize_t bytes = read(pollfd.fd, &events, sizeof(events));
if (bytes == sizeof(events))
{
- if (events == UINT64_MAX-1)
+ if (events >= END_EVENT)
{
for (auto & elem : mMapShPoll)
{
@@ -80,6 +80,7 @@ CAmSocketHandler::CAmSocketHandler() :
elem.second.state = poll_states_e::UNINIT;
}
mDispatchDone = true;
+ }
return;
}
@@ -145,7 +146,14 @@ void CAmSocketHandler::start_listenting()
// fallthrough
case poll_states_e::REMOVE:
- fdPollIt = fdPollingArray.erase(fdPollIt);
+ /* The first check is needed for the restart behavior were an element is marked
+ * as removed but not part of the polling array - which is stored on heap.
+ * The second check is needed in case a map element was inserted newly but was
+ * directly marked after as REMOVE but in between there was no sync. of the
+ * polling array processed.
+ */
+ if (fdPollIt != fdPollingArray.end() && fdPollIt->fd == elem.pollfdValue.fd)
+ fdPollIt = fdPollingArray.erase(fdPollIt);
it = mMapShPoll.erase(it);
continue;
@@ -246,7 +254,7 @@ void CAmSocketHandler::exit_mainloop()
stop_listening();
//fire the ending filedescriptor
- const uint64_t events = UINT64_MAX-1;
+ const uint64_t events = END_EVENT;
if (write(mEventFd, &events, sizeof(events)) < 0)
{
//Failed to write to event fd...