From 2c9b50cabd5563b0c81ca7cf4893b5ea08c6bc92 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Tue, 2 Nov 2004 13:26:50 +0000 Subject: only attempt to reconnect to shout server every 60 seconds git-svn-id: https://svn.musicpd.org/mpd/trunk@2472 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/audioOutputs/audioOutput_shout.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/audioOutputs/audioOutput_shout.c b/src/audioOutputs/audioOutput_shout.c index 8b8e789fb..82c793c99 100644 --- a/src/audioOutputs/audioOutput_shout.c +++ b/src/audioOutputs/audioOutput_shout.c @@ -30,11 +30,14 @@ #include #include #include +#include #include #include #include +#define CONN_ATTEMPT_INTERVAL 60 + static int shoutInitCount = 0; /* lots of this code blatantly stolent from bossogg/bossao2 */ @@ -68,6 +71,9 @@ typedef struct _ShoutData { MpdTag * tag; int tagToSend; + + int connAttempts; + time_t lastAttempt; } ShoutData; static ShoutData * newShoutData() { @@ -81,6 +87,8 @@ static ShoutData * newShoutData() { ret->tagToSend = 0; ret->bitrate = -1; ret->quality = -1.0; + ret->connAttempts = 0; + ret->lastAttempt = 0; return ret; } @@ -370,12 +378,20 @@ static int initEncoder(ShoutData * sd) { static int myShout_openShoutConn(AudioOutput * audioOutput) { ShoutData * sd = (ShoutData *)audioOutput->data; + time_t t = time(NULL); - if(shout_open(sd->shoutConn) != SHOUTERR_SUCCESS) - { - ERROR("problem opening connection to shout server: %s\n", - shout_get_error(sd->shoutConn)); + sd->connAttempts++; + if(t - sd->lastAttempt < CONN_ATTEMPT_INTERVAL) { + return -1; + } + + sd->lastAttempt = t; + + if(shout_open(sd->shoutConn) != SHOUTERR_SUCCESS) { + ERROR("problem opening connection to shout server (attempt %i):" + " %s\n", sd->connAttempts, + shout_get_error(sd->shoutConn)); return -1; } @@ -404,8 +420,7 @@ static int myShout_openShoutConn(AudioOutput * audioOutput) { } } - /*if(sd->tag) freeMpdTag(sd->tag); - sd->tag = NULL;*/ + sd->connAttempts = 0; return 0; } -- cgit v1.2.3