]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
* Add exponential backoff for reconnect attempt in code word client.
authorAndreas Öman <andreas@lonelycoder.com>
Sat, 18 Jul 2009 19:10:49 +0000 (19:10 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Sat, 18 Jul 2009 19:10:49 +0000 (19:10 +0000)
    Ticket #80

debian/changelog
src/cwc.c

index 0b1346acf2f976a791896af58c9085a67de1f360..c801cb35daeb0c670d91a13b63f6aa5ec575bf05 100644 (file)
@@ -66,6 +66,9 @@ hts-tvheadend (2.3) hts; urgency=low
 
   * Fix a bug causing channel <> tags mapping not to be restored on load.
 
+  * Add exponential backoff for reconnect attempt in code word client.
+    Ticket #80
+
 hts-tvheadend (2.2) hts; urgency=low
 
   * Set $HOME so forked processes (XMLTV) will have correct environment
index 2d5d6a7eaa507aba73c5f5018d155ea6ada69b29..1efa6f52f871f76bf0f66f4b20ab201eb99286b7 100644 (file)
--- a/src/cwc.c
+++ b/src/cwc.c
@@ -141,6 +141,8 @@ typedef struct cwc_transport {
 typedef struct cwc {
   int cwc_fd;
 
+  int cwc_retry_delay;
+
   pthread_mutex_t cwc_send_mutex;
 
   pthread_cond_t cwc_cond;
@@ -697,6 +699,10 @@ cwc_session(cwc_t *cwc)
   if(cwc_decode_card_data_reply(cwc, cwc->cwc_buf, r) < 0)
     return;
 
+  /**
+   * Ok, connection good, reset retry delay to zero
+   */
+  cwc->cwc_retry_delay = 0;
 
   /**
    * We do all requests from now on in a separate thread
@@ -785,11 +791,16 @@ cwc_thread(void *aux)
     cwc->cwc_fd = -1;
     close(fd);
     cwc->cwc_caid = 0;
-    tvhlog(LOG_INFO, "cwc", "Disconnected from %s", cwc->cwc_hostname);
+    tvhlog(LOG_INFO, "cwc", "Disconnected from %s, retry in %d seconds",
+          cwc->cwc_hostname, cwc->cwc_retry_delay);
 
     pthread_mutex_unlock(&global_lock);
-    sleep(1);
+    sleep(cwc->cwc_retry_delay);
     pthread_mutex_lock(&global_lock);
+
+    cwc->cwc_retry_delay = cwc->cwc_retry_delay * 2 + 1;
+    if(cwc->cwc_retry_delay > 120)
+      cwc->cwc_retry_delay = 120;
   }
 
   tvhlog(LOG_INFO, "cwc", "%s destroyed", cwc->cwc_hostname);