From: Anthony Minessale Date: Tue, 6 Jan 2009 00:18:57 +0000 (+0000) Subject: cleanup and fix disconnect race X-Git-Tag: v1.0.3~810 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbac44c53a2edb52e4f9128f039160c127801c77;p=thirdparty%2Ffreeswitch.git cleanup and fix disconnect race git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11078 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- diff --git a/libs/esl/fs_cli.c b/libs/esl/fs_cli.c index fcc36b2234..85394dc497 100644 --- a/libs/esl/fs_cli.c +++ b/libs/esl/fs_cli.c @@ -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; } diff --git a/libs/esl/src/esl.c b/libs/esl/src/esl.c index 287fa1a888..658e15c71d 100644 --- a/libs/esl/src/esl.c +++ b/libs/esl/src/esl.c @@ -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)