]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
cleanup and fix disconnect race
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 6 Jan 2009 00:18:57 +0000 (00:18 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 6 Jan 2009 00:18:57 +0000 (00:18 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11078 d0543943-73ff-0310-b7d9-9358b9ac24b2

libs/esl/fs_cli.c
libs/esl/src/esl.c

index fcc36b2234084c7b47dfb90b7abde8c076ff9f9f..85394dc497636046832aa8e27c183191a4d467de 100644 (file)
@@ -618,6 +618,7 @@ int main(int argc, char *argv[])
        }
 
        if (esl_connect(&handle, profile->host, profile->port, profile->pass)) {
+               esl_global_set_default_logger(3);
                esl_log(ESL_LOG_ERROR, "Error Connecting [%s]\n", handle.err);
                return -1;
        }
index 287fa1a8885ad338582aeaed22c112beeebc53fb..658e15c71dbbcb366c9434f1eb7198044f075916 100644 (file)
@@ -570,24 +570,32 @@ ESL_DECLARE(esl_status_t) esl_connect(esl_handle_t *handle, const char *host, es
 
 ESL_DECLARE(esl_status_t) esl_disconnect(esl_handle_t *handle)
 {
+       esl_mutex_t *mutex = handle->mutex;
+       esl_status_t status = ESL_SUCCESS;
+       
+       if (mutex) {
+               esl_mutex_lock(mutex);
+       }
+
        esl_event_safe_destroy(&handle->last_event);
        esl_event_safe_destroy(&handle->last_sr_event);
        esl_event_safe_destroy(&handle->last_ievent);
        esl_event_safe_destroy(&handle->info_event);
 
-       if (handle->mutex) {
-               esl_mutex_destroy(&handle->mutex);
-       }
-
        if (handle->sock != ESL_SOCK_INVALID) {
                closesocket(handle->sock);
                handle->sock = ESL_SOCK_INVALID;
-               return ESL_SUCCESS;
        }
        
        handle->connected = 0;
 
-       return ESL_FAIL;
+       if (mutex) {
+               esl_mutex_unlock(mutex);
+               esl_mutex_destroy(&mutex);
+       }
+
+
+       return status;
 }
 
 ESL_DECLARE(esl_status_t) esl_recv_event_timed(esl_handle_t *handle, uint32_t ms, esl_event_t **save_event)