From 12880b7e8442a19fbe2955fb23746166f8e0029a Mon Sep 17 00:00:00 2001 From: flamin Date: Mon, 8 Sep 2014 11:39:04 -0400 Subject: [PATCH] Fix ping timeout handling and ignore automake files --- .gitignore | 3 +++ src/main.cpp | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bfea486..0855f8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# automake related +.dirstamp + # Compiled Object files *.slo *.lo diff --git a/src/main.cpp b/src/main.cpp index a805141..fd27df9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -162,9 +162,22 @@ void Main::loop(const string & device) { } commands.pop(); } + int retriesRemaining = 3; while( running && !libcec_cond.timed_wait(libcec_lock, boost::posix_time::seconds(43)) ) { - running = cec.ping(); + // Since libcec's CAdapterPingThread::Process() tries pinging 3 times before raising a + // connection lost alert, lets also make 3 attempts otherwise we'll stop running + // before our alert handling gets a chance to do its job + bool pinged = false; + if( retriesRemaining > 0 && !(pinged = cec.ping()) ) + { + --retriesRemaining; + boost::this_thread::sleep(boost::posix_time::milliseconds(CEC_DEFAULT_TRANSMIT_RETRY_WAIT)); + } + else + { + running = pinged; + } } } while( running );