[Freeswitch-svn] [commit] r11404 - in freeswitch/branches/1.0/libs/esl: . src

FreeSWITCH SVN mikej at freeswitch.org
Thu Jan 22 14:07:53 PST 2009


Author: mikej
Date: Thu Jan 22 16:07:53 2009
New Revision: 11404

Log:
libesl: fix disconnect failure (r:11078,11083)

Modified:
   freeswitch/branches/1.0/libs/esl/fs_cli.c
   freeswitch/branches/1.0/libs/esl/src/esl.c

Modified: freeswitch/branches/1.0/libs/esl/fs_cli.c
==============================================================================
--- freeswitch/branches/1.0/libs/esl/fs_cli.c	(original)
+++ freeswitch/branches/1.0/libs/esl/fs_cli.c	Thu Jan 22 16:07:53 2009
@@ -618,6 +618,7 @@
 	}
 
 	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;
 	}

Modified: freeswitch/branches/1.0/libs/esl/src/esl.c
==============================================================================
--- freeswitch/branches/1.0/libs/esl/src/esl.c	(original)
+++ freeswitch/branches/1.0/libs/esl/src/esl.c	Thu Jan 22 16:07:53 2009
@@ -368,6 +368,10 @@
 {
 	char *txt;
 
+	if (!handle->connected) {
+		return ESL_FAIL;
+	}
+
 	esl_event_serialize(handle->last_ievent, &txt, ESL_TRUE);
 
 	esl_log(ESL_LOG_DEBUG, "SEND EVENT\n%s\n", txt);
@@ -388,6 +392,10 @@
 	char arg_buf[512] = "";
 	char send_buf[1292] = "";
 	
+	if (!handle->connected) {
+		return ESL_FAIL;
+	}
+
 	if (uuid) {
 		snprintf(cmd_buf, sizeof(cmd_buf), "sendmsg %s", uuid);
 	}
@@ -570,24 +578,33 @@
 
 ESL_DECLARE(esl_status_t) esl_disconnect(esl_handle_t *handle)
 {
+	esl_mutex_t *mutex = handle->mutex;
+	esl_status_t status = ESL_FAIL;
+	
+	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;
+		status = 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)
@@ -597,6 +614,10 @@
 	int max, activity;
 	esl_status_t status = ESL_SUCCESS;
 
+	if (!handle->connected) {
+		return ESL_FAIL;
+	}
+
 	tv.tv_usec = ms * 1000;
 
 	esl_mutex_lock(handle->mutex);
@@ -652,6 +673,11 @@
 	esl_ssize_t len;
 	int zc = 0;
 	
+
+	if (!handle->connected) {
+		return ESL_FAIL;
+	}
+
 	esl_mutex_lock(handle->mutex);
 
 	esl_event_safe_destroy(&handle->last_event);
@@ -850,6 +876,10 @@
 {
 	const char *e = cmd + strlen(cmd) -1;
 	
+	if (!handle->connected) {
+		return ESL_FAIL;
+	}
+
 	esl_log(ESL_LOG_DEBUG, "SEND\n%s\n", cmd);
 	
 	if (send(handle->sock, cmd, strlen(cmd), 0) != (int)strlen(cmd)) {
@@ -874,6 +904,10 @@
 	const char *hval;
 	esl_status_t status;
 	
+	if (!handle->connected) {
+		return ESL_FAIL;
+	}
+
 	esl_mutex_lock(handle->mutex);
 
 	if ((status = esl_send(handle, cmd))) {



More information about the Freeswitch-svn mailing list