From: Lars Op den Kamp Date: Mon, 27 Feb 2012 19:40:08 +0000 (+0100) Subject: cec: don't wait for the full timeout to pass in CCECProcessor::OpenConnection(),... X-Git-Tag: upstream/2.2.0~1^2~33^2~17 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3b5e433aedcade91b053d591bf19b02605ef8697;p=deb_libcec.git cec: don't wait for the full timeout to pass in CCECProcessor::OpenConnection(), but retry to connect 2 times. fixes 'port busy' errors when initialising libCEC --- diff --git a/include/cectypes.h b/include/cectypes.h index 5b05b13..91fd94d 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -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 diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 2391ca7..a4bbcbc 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -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)