From: Jan Cybulski Date: Mon, 22 Jun 2015 13:18:55 +0000 (+0200) Subject: Return from main after timeout on idle. X-Git-Tag: submit/tizen_common/20160317.155115~66 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6329079f1d515fc0aedf155b3eaec16f95cf9133;p=platform%2Fcore%2Fapi%2Fusb-host.git Return from main after timeout on idle. Change-Id: Ic50f4f6e1c7edf7e7814f42fb2b054bc9f76e90e Signed-off-by: Jan Cybulski --- diff --git a/USD/src/main/socket-manager.cpp b/USD/src/main/socket-manager.cpp index 7a527f9..935635c 100644 --- a/USD/src/main/socket-manager.cpp +++ b/USD/src/main/socket-manager.cpp @@ -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 diff --git a/USD/src/main/socket-manager.h b/USD/src/main/socket-manager.h index db61335..95abb93 100644 --- a/USD/src/main/socket-manager.h +++ b/USD/src/main/socket-manager.h @@ -121,6 +121,7 @@ protected: fd_set m_writeSet; int m_maxDesc; bool m_working; + bool m_starting; std::mutex m_eventQueueMutex; std::queue m_writeBufferQueue; std::queue m_writeDataQueue;