Return from main after timeout on idle.
authorJan Cybulski <j.cybulski@samsung.com>
Mon, 22 Jun 2015 13:18:55 +0000 (15:18 +0200)
committerStanislaw Wadas <s.wadas@samsung.com>
Wed, 2 Dec 2015 12:45:16 +0000 (13:45 +0100)
Change-Id: Ic50f4f6e1c7edf7e7814f42fb2b054bc9f76e90e
Signed-off-by: Jan Cybulski <j.cybulski@samsung.com>
USD/src/main/socket-manager.cpp
USD/src/main/socket-manager.h

index 7a527f92f71f1fc6dd3a0bbcd79f2533f73e43ec..935635c2a0a78bec5cc73dcb7a035854b15b3961 100644 (file)
@@ -338,7 +338,7 @@ void SocketManager::MainLoop() {
 
     // Daemon is ready to work.
     sd_notify(0, "READY=1");
-
+    m_starting = true;
     m_working = true;
     while(m_working) {
         fd_set readSet = m_readSet;
@@ -366,22 +366,28 @@ void SocketManager::MainLoop() {
                 m_timeoutQueue.push(tm);
             }
         }
-
-        if (m_timeoutQueue.empty()) {
-            LogDebug("No usaable timeout found.");
-            ptrTimeout = NULL; // select will wait without timeout
-        } else {
-            time_t currentTime = time(NULL);
-            auto &pqTimeout = m_timeoutQueue.top();
-
-            // 0 means that select won't block and socket will be closed ;-)
-            ptrTimeout->tv_sec =
-              currentTime < pqTimeout.time ? pqTimeout.time - currentTime : 0;
+        if (m_starting) {
+            ptrTimeout->tv_sec = SOCKET_TIMEOUT;
             ptrTimeout->tv_usec = 0;
-//            LogDebug("Set up timeout: " << (int)ptrTimeout->tv_sec
-//                << " seconds. Socket: " << pqTimeout.sock);
+            m_starting = false;
+        } else {
+            if (m_timeoutQueue.empty()) {
+                LogDebug("No useable timeout found.");
+                ptrTimeout->tv_sec = 0;
+                ptrTimeout->tv_usec = 0;
+                MainLoopStop();
+            } else {
+                time_t currentTime = time(NULL);
+                auto &pqTimeout = m_timeoutQueue.top();
+
+                // 0 means that select won't block and socket will be closed ;-)
+                ptrTimeout->tv_sec =
+                  currentTime < pqTimeout.time ? pqTimeout.time - currentTime : 0;
+                ptrTimeout->tv_usec = 0;
+//                LogDebug("Set up timeout: " << (int)ptrTimeout->tv_sec
+//                    << " seconds. Socket: " << pqTimeout.sock);
+            }
         }
-
         int ret = select(m_maxDesc+1, &readSet, &writeSet, NULL, ptrTimeout);
 
         if (0 == ret) { // timeout
index db613353e769cb046ef0be742854d74c924c6cd5..95abb93f84610c447e7d7d04c87cace246132e38 100644 (file)
@@ -121,6 +121,7 @@ protected:
     fd_set m_writeSet;
     int m_maxDesc;
     bool m_working;
+    bool m_starting;
     std::mutex m_eventQueueMutex;
     std::queue<WriteBuffer> m_writeBufferQueue;
     std::queue<WriteData> m_writeDataQueue;