]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
connection timeout
authorRupa Schomaker <rupa@rupa.com>
Mon, 4 May 2009 13:42:52 +0000 (13:42 +0000)
committerRupa Schomaker <rupa@rupa.com>
Mon, 4 May 2009 13:42:52 +0000 (13:42 +0000)
(very) slow connection timeout
Timeouts needed to avoid deadlock between read thread and file close.  If
read thread never returns -- the file can never be closed.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13224 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/formats/mod_shout/mod_shout.c

index 5e952af326fd6938aec77532217580a69a201a76..a8d14d1eea9678b5fcbecfd3743aa073767cb691 100644 (file)
@@ -97,6 +97,7 @@ mpg123_handle *our_mpg123_new(const char* decoder, int *error)
 
 struct shout_context {
        shout_t *shout;
+       char curl_error_buff[CURL_ERROR_SIZE];
        lame_global_flags *gfp;
        char *stream_url;
        switch_mutex_t *audio_mutex;
@@ -512,6 +513,7 @@ static size_t stream_callback(void *ptr, size_t size, size_t nmemb, void *data)
 static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void *obj)
 {
        CURL *curl_handle = NULL;
+       CURLcode cc;
        shout_context_t *context = (shout_context_t *) obj;
        
        switch_thread_rwlock_rdlock(context->rwlock);
@@ -523,7 +525,15 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
        curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, stream_callback);
        curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) context);
        curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "FreeSWITCH(mod_shout)/1.0");
-       curl_easy_perform(curl_handle);
+       curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
+       curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 30); /* eventually timeout connect */
+       curl_easy_setopt(curl_handle, CURLOPT_LOW_SPEED_LIMIT, 100); /* handle trickle connections */
+       curl_easy_setopt(curl_handle, CURLOPT_LOW_SPEED_TIME, 30);
+       curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, context->curl_error_buff);
+       cc = curl_easy_perform(curl_handle);
+       if (cc && cc != CURLE_WRITE_ERROR) { /* write error is ok, we just exited from callback early */
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "CURL returned error:[%d] %s : %s [%s]\n", cc, curl_easy_strerror(cc), context->curl_error_buff, context->stream_url);
+       }
        curl_easy_cleanup(curl_handle);
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Read Thread Done\n");