]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8028: [mod_shout] fix random sockets being closed regression from FS-7621
authorAnthony Minessale <anthm@freeswitch.org>
Sun, 23 Aug 2015 17:42:27 +0000 (12:42 -0500)
committerMichael Jerris <mike@jerris.com>
Sun, 23 Aug 2015 22:39:31 +0000 (17:39 -0500)
src/mod/formats/mod_shout/mod_shout.c

index 547003cf9801f63ac78f0675929cada5d0bd6393..907b628900fe6698c504fb10d2a8bc89fe2c0cbe 100644 (file)
@@ -147,9 +147,12 @@ static inline void free_context(shout_context_t *context)
                switch_mutex_unlock(context->audio_mutex);
 
                if (context->stream_url) {
+                       switch_mutex_lock(context->audio_mutex);
                        if (context->curlfd > -1) {
                                shutdown(context->curlfd, 2);
+                               context->curlfd = -1;
                        }
+                       switch_mutex_unlock(context->audio_mutex);
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for stream to terminate: %s\n", context->stream_url);
                        if (context->read_stream_thread) {
                                switch_thread_join(&st, context->read_stream_thread);
@@ -466,7 +469,9 @@ static int sockopt_callback(void *clientp, curl_socket_t curlfd,
 {
        shout_context_t *context = (shout_context_t *) clientp;
 
+       switch_mutex_lock(context->audio_mutex);
        context->curlfd = curlfd;
+       switch_mutex_unlock(context->audio_mutex);
        
        return 0;
 }
@@ -480,7 +485,9 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
        shout_context_t *context = (shout_context_t *) obj;
 
        switch_thread_rwlock_rdlock(context->rwlock);
+       switch_mutex_lock(context->audio_mutex);
        context->curlfd = -1;
+       switch_mutex_unlock(context->audio_mutex);
        curl_handle = switch_curl_easy_init();
        switch_curl_easy_setopt(curl_handle, CURLOPT_URL, context->stream_url);
        curl_easy_setopt(curl_handle, CURLOPT_PROGRESSFUNCTION, progress_callback);
@@ -500,6 +507,10 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
 
        cc = switch_curl_easy_perform(curl_handle);
 
+       switch_mutex_lock(context->audio_mutex);
+       context->curlfd = -1;
+       switch_mutex_unlock(context->audio_mutex);
+
        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, switch_curl_easy_strerror(cc),
                                                  context->curl_error_buff, context->stream_url);