From 2fcb7fe72bb63d4b66e66aa1a4ac28ac640b1f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Sat, 18 Jul 2009 19:10:49 +0000 Subject: [PATCH] * Add exponential backoff for reconnect attempt in code word client. Ticket #80 --- debian/changelog | 3 +++ src/cwc.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 0b1346ac..c801cb35 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 diff --git a/src/cwc.c b/src/cwc.c index 2d5d6a7e..1efa6f52 100644 --- 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);