cec: don't wait for the full timeout to pass in CCECProcessor::OpenConnection(),...
authorLars Op den Kamp <lars@opdenkamp.eu>
Mon, 27 Feb 2012 19:40:08 +0000 (20:40 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Mon, 27 Feb 2012 19:40:08 +0000 (20:40 +0100)
include/cectypes.h
src/lib/CECProcessor.cpp

index 5b05b13210d90d7436868cec3153260a91c78edb..91fd94d098aee5445a141b3ccf1991838240cc6d 100644 (file)
@@ -72,6 +72,7 @@ namespace CEC {
 #define CEC_BUTTON_TIMEOUT           500
 #define CEC_POWER_STATE_REFRESH_TIME 30000
 #define CEC_FW_VERSION_UNKNOWN       0xFFFF
+#define CEC_CONNECT_TRIES            3
 
 #define CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE  1
 #define CEC_DEFAULT_SETTING_ACTIVATE_SOURCE       1
index 2391ca7e411d9b8d32c7fc060e7adef96f1003fa..a4bbcbc8e0b7ed0d6acb30f0190ed6f21b67a5dd 100644 (file)
@@ -181,16 +181,14 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint
     return bReturn;
   }
 
-  uint64_t iNow = GetTimeMs();
-  uint64_t iTarget = iTimeoutMs > 0 ? iNow + iTimeoutMs : iNow + CEC_DEFAULT_TRANSMIT_WAIT;
+  CTimeout timeout(iTimeoutMs > 0 ? iTimeoutMs : CEC_DEFAULT_TRANSMIT_WAIT);
 
   /* open a new connection */
   unsigned iConnectTry(0);
-  while (iNow < iTarget && (bReturn = m_communication->Open(this, iTimeoutMs)) == false)
+  while (timeout.TimeLeft() > 0 && (bReturn = m_communication->Open(this, (timeout.TimeLeft() / CEC_CONNECT_TRIES))) == false)
   {
     CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry);
     Sleep(500);
-    iNow = GetTimeMs();
   }
 
   if (bReturn)