* fixed sockethandler timespec issues
authorchristian mueller <christian.ei.mueller@bmw.de>
Fri, 30 Dec 2011 10:27:33 +0000 (11:27 +0100)
committerchristian mueller <christian.ei.mueller@bmw.de>
Fri, 30 Dec 2011 10:27:33 +0000 (11:27 +0100)
AudioManagerDaemon/src/SocketHandler.cpp
AudioManagerDaemon/test/CMakeLists.txt
AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp
includes/SocketHandler.h

index 9c10743..b749fbb 100644 (file)
@@ -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)
 }
 
 
+
+
+
+
index 7f8c054..f00ec41 100644 (file)
@@ -18,4 +18,4 @@ FIND_PACKAGE(GTest REQUIRED)
 add_subdirectory (database)
 add_subdirectory (routingInterface)
 add_subdirectory (controlInterface)
-#add_subdirectory (sockethandler)
+add_subdirectory (sockethandler)
index 4d6619e..cf551aa 100644 (file)
@@ -186,6 +186,7 @@ TEST(sockethandlerTest,playWithSockets)
 
 TEST(sockethandlerTest,playWithTimers)
 {
+       gDispatchDone=0;
        SocketHandler myHandler;
        timerCallBack testCallback(&myHandler);
        timespec timeoutTime, timeout2, timeout3, timeout4;
index 5d72f3e..db81365 100644 (file)
@@ -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;
 };