[xiph-commits] r18357 - icecast/trunk/ices/src

ph3-der-loewe at svn.xiph.org ph3-der-loewe at svn.xiph.org
Thu Jun 7 09:44:26 PDT 2012


Author: ph3-der-loewe
Date: 2012-06-07 09:44:26 -0700 (Thu, 07 Jun 2012)
New Revision: 18357

Modified:
   icecast/trunk/ices/src/cfgparse.c
   icecast/trunk/ices/src/cfgparse.h
   icecast/trunk/ices/src/stream.c
Log:
Added optional support to retry initial connection using <retry-initial>.
Thanks to Eric Faurot for inital patch.
(close #994)


Modified: icecast/trunk/ices/src/cfgparse.c
===================================================================
--- icecast/trunk/ices/src/cfgparse.c	2012-06-07 15:57:59 UTC (rev 18356)
+++ icecast/trunk/ices/src/cfgparse.c	2012-06-07 16:44:26 UTC (rev 18357)
@@ -4,6 +4,7 @@
  * $Id: cfgparse.c,v 1.10 2004/03/11 17:16:08 karl Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at xiph.org>
+ * Copyright (c) 2006 Eric Faurot
  *
  * This program is distributed under the terms of the GNU General
  * Public License, version 2. You may use, modify, and redistribute
@@ -54,6 +55,7 @@
 #define DEFAULT_RESAMPLE 0
 #define DEFAULT_RECONN_DELAY 2
 #define DEFAULT_RECONN_ATTEMPTS 10
+#define DEFAULT_RETRY_INIT 0
 #define DEFAULT_MAXQUEUELENGTH 100 /* Make it _BIG_ by default */
 #define DEFAULT_SAVEFILENAME NULL /* NULL == don't save */
 
@@ -138,6 +140,7 @@
     instance->resampleoutrate = DEFAULT_RESAMPLE;
     instance->reconnect_delay = DEFAULT_RECONN_DELAY;
     instance->reconnect_attempts = DEFAULT_RECONN_ATTEMPTS;
+    instance->retry_initial_connection = DEFAULT_RETRY_INIT;
     instance->max_queue_length = DEFAULT_MAXQUEUELENGTH;
     instance->savefilename = DEFAULT_SAVEFILENAME;
 
@@ -255,6 +258,8 @@
             SET_INT(instance->reconnect_delay);
         else if(strcmp(node->name, "reconnectattempts") == 0)
             SET_INT(instance->reconnect_attempts);
+        else if(strcmp(node->name, "retry-initial") == 0)
+            SET_INT(instance->retry_initial_connection);
         else if(strcmp(node->name, "maxqueuelength") == 0)
             SET_INT(instance->max_queue_length);
         else if(strcmp(node->name, "downmix") == 0)

Modified: icecast/trunk/ices/src/cfgparse.h
===================================================================
--- icecast/trunk/ices/src/cfgparse.h	2012-06-07 15:57:59 UTC (rev 18356)
+++ icecast/trunk/ices/src/cfgparse.h	2012-06-07 16:44:26 UTC (rev 18357)
@@ -4,6 +4,7 @@
  * $Id: cfgparse.h,v 1.7 2004/03/11 17:16:08 karl Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at xiph.org>
+ * Copyright (c) 2006 Eric Faurot
  *
  * This program is distributed under the terms of the GNU General
  * Public License, version 2. You may use, modify, and redistribute
@@ -25,7 +26,7 @@
     struct _module_param_tag *next;
 } module_param_t;
 
-/* FIXME: orward declaraction because my headers are a mess. */
+/* FIXME: forward declaraction because my headers are a mess. */
 struct buffer_queue;
 
 typedef struct _instance_tag
@@ -37,6 +38,7 @@
     char *mount;
     int reconnect_delay;
     int reconnect_attempts;
+    int retry_initial_connection;
     int encode;
     int downmix;
     int resampleinrate;

Modified: icecast/trunk/ices/src/stream.c
===================================================================
--- icecast/trunk/ices/src/stream.c	2012-06-07 15:57:59 UTC (rev 18356)
+++ icecast/trunk/ices/src/stream.c	2012-06-07 16:44:26 UTC (rev 18357)
@@ -50,7 +50,7 @@
  */
 void *ices_instance_stream(void *arg)
 {
-    int ret, shouterr;
+    int ret, shouterr, initial_attempts;
     ref_buffer *buffer;
     stream_description *sdsc = arg;
     instance_t *stream = sdsc->stream;
@@ -214,6 +214,8 @@
             LOG_INFO1("Saving stream to file %s", stream->savefilename);
     }
 
+    initial_attempts = 0;
+retry:
     if((shouterr = shout_open(sdsc->shout)) == SHOUTERR_SUCCESS)
     {
         LOG_INFO3("Connected to server: %s:%d%s", 
@@ -343,6 +345,17 @@
     }
     else
     {
+	if (stream->retry_initial_connection &&
+	    (initial_attempts++ < stream->reconnect_attempts ||
+	     stream->reconnect_attempts == -1) && 
+	    !ices_config->shutdown)
+	{
+	    shout_close(sdsc->shout);
+	    LOG_WARN4("Retrying connection to %s:%d (%s: %s)", 
+               shout_get_host(sdsc->shout),shout_get_port(sdsc->shout), shout_get_error(sdsc->shout), strerror(errno));
+	    thread_sleep (stream->reconnect_delay*1000000);
+	    goto retry;
+	}
         LOG_ERROR4("Failed initial connect to %s:%d (%s: %s)", 
                 shout_get_host(sdsc->shout),shout_get_port(sdsc->shout), shout_get_error(sdsc->shout), strerror(errno));
     }



More information about the commits mailing list