diff options
-rw-r--r-- | AudioManagerDaemon/src/SocketHandler.cpp | 49 | ||||
-rw-r--r-- | AudioManagerDaemon/test/CMakeLists.txt | 2 | ||||
-rw-r--r-- | AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp | 1 | ||||
-rw-r--r-- | includes/SocketHandler.h | 2 |
4 files changed, 32 insertions, 22 deletions
diff --git a/AudioManagerDaemon/src/SocketHandler.cpp b/AudioManagerDaemon/src/SocketHandler.cpp index 9c10743..b749fbb 100644 --- a/AudioManagerDaemon/src/SocketHandler.cpp +++ b/AudioManagerDaemon/src/SocketHandler.cpp @@ -34,6 +34,8 @@ #include <dlt/dlt.h> #include <signal.h> + +#include <iostream> //todo: implement time correction if timer was interrupted by call DLT_IMPORT_CONTEXT(AudioManager) @@ -48,11 +50,11 @@ SocketHandler::SocketHandler() mLastInsertedHandle(0), mLastInsertedPollHandle(0), mRecreatePollfds(true), - mTimeout(), - mTimeoutPointer(NULL) + mTimeout() { - mTimeout.tv_nsec=0; - mTimeout.tv_sec=0; + mTimeout.tv_nsec=-1; + mTimeout.tv_sec=-1; + gDispatchDone=0; } SocketHandler::~SocketHandler() @@ -101,7 +103,9 @@ void SocketHandler::start_listenting() //block until something is on a filedescriptor #ifdef WITH_PPOLL - if((pollStatus=ppoll(&mfdPollingArray.front(),mfdPollingArray.size(),mTimeoutPointer,&sigmask))<0) + + timespec buffertime; + if((pollStatus=ppoll(&mfdPollingArray.front(),mfdPollingArray.size(),insertTime(buffertime),&sigmask))<0) { if(errno==EINTR) { @@ -116,7 +120,7 @@ void SocketHandler::start_listenting() } #else - sigprocmask (SIG_SETMASK, &mask, &oldmask); + //sigprocmask (SIG_SETMASK, &mask, &oldmask); if((pollStatus=poll(&mfdPollingArray.front(),mfdPollingArray.size(),timespec2ms(mTimeout)))<0) { @@ -129,7 +133,7 @@ void SocketHandler::start_listenting() DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("SocketHandler::start_listenting poll returned with error"),DLT_INT(errno)); exit(0); } - sigprocmask (SIG_SETMASK, &oldmask, NULL); + //sigprocmask (SIG_SETMASK, &oldmask, NULL); #endif if (pollStatus!=0) //only check filedescriptors if there was a change @@ -361,13 +365,11 @@ am_Error_e SocketHandler::stopTimer(const sh_timerHandle_t handle) if (!mListActiveTimer.empty()) { mTimeout=mListActiveTimer.front().countdown; - mTimeoutPointer=&mTimeout; } else { - mTimeout.tv_nsec=0; - mTimeout.tv_sec=0; - mTimeoutPointer=NULL; + mTimeout.tv_nsec=-1; + mTimeout.tv_sec=-1; } return E_OK; } @@ -423,13 +425,11 @@ void SocketHandler::timerUp() //substract the old value from all timers in the list std::for_each(mListActiveTimer.begin(),mListActiveTimer.end(),SubstractTime(mTimeout)); mTimeout=mListActiveTimer.front().countdown; - mTimeoutPointer=&mTimeout; } else { - mTimeout.tv_nsec=0; - mTimeout.tv_sec=0; - mTimeoutPointer=NULL; + mTimeout.tv_nsec=-1; + mTimeout.tv_sec=-1; } } @@ -441,13 +441,11 @@ void SocketHandler::initTimer() if(!mListActiveTimer.empty()) { mTimeout=mListActiveTimer.front().countdown; - mTimeoutPointer=&mTimeout; } else { - mTimeout.tv_nsec=0; - mTimeout.tv_sec=0; - mTimeoutPointer=NULL; + mTimeout.tv_nsec=-1; + mTimeout.tv_sec=-1; } } @@ -459,7 +457,14 @@ void SocketHandler::initTimer() */ inline int SocketHandler::timespec2ms(const timespec & time) { - return (time.tv_nsec == 0 && time.tv_sec == 0) ? -1 : time.tv_sec * 1000 + time.tv_nsec / 1000000; + return (time.tv_nsec == -1 && time.tv_sec == -1) ? -1 : time.tv_sec * 1000 + time.tv_nsec / 1000000; +} + +inline timespec* am::SocketHandler::insertTime(timespec& buffertime) +{ + buffertime.tv_nsec=mTimeout.tv_nsec; + buffertime.tv_sec=mTimeout.tv_sec; + return (mTimeout.tv_nsec == -1 && mTimeout.tv_sec == -1) ? NULL : &buffertime; } /** @@ -486,3 +491,7 @@ void SocketHandler::CopyPollfd::operator ()(const sh_poll_s & row) } + + + + diff --git a/AudioManagerDaemon/test/CMakeLists.txt b/AudioManagerDaemon/test/CMakeLists.txt index 7f8c054..f00ec41 100644 --- a/AudioManagerDaemon/test/CMakeLists.txt +++ b/AudioManagerDaemon/test/CMakeLists.txt @@ -18,4 +18,4 @@ FIND_PACKAGE(GTest REQUIRED) add_subdirectory (database) add_subdirectory (routingInterface) add_subdirectory (controlInterface) -#add_subdirectory (sockethandler) +add_subdirectory (sockethandler) diff --git a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp b/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp index 4d6619e..cf551aa 100644 --- a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp +++ b/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp @@ -186,6 +186,7 @@ TEST(sockethandlerTest,playWithSockets) TEST(sockethandlerTest,playWithTimers) { + gDispatchDone=0; SocketHandler myHandler; timerCallBack testCallback(&myHandler); timespec timeoutTime, timeout2, timeout3, timeout4; diff --git a/includes/SocketHandler.h b/includes/SocketHandler.h index 5d72f3e..db81365 100644 --- a/includes/SocketHandler.h +++ b/includes/SocketHandler.h @@ -108,6 +108,7 @@ private: void initTimer(); void timerUp(); int timespec2ms(const timespec& time); + timespec* insertTime(timespec& buffertime); static bool compareCountdown(const timer_s& a, const timer_s& b) { return (a.countdown.tv_sec==b.countdown.tv_sec) ? (a.countdown.tv_nsec < b.countdown.tv_nsec) : (a.countdown.tv_sec < b.countdown.tv_sec); @@ -127,7 +128,6 @@ private: sh_timerHandle_t mLastInsertedHandle; sh_pollHandle_t mLastInsertedPollHandle; timespec mTimeout; - timespec *mTimeoutPointer; //we need this because for infinite loops we need to set this to NULL mTimeout -1 is not working with ppoll bool mRecreatePollfds; }; |