Revision
16766
Author
sathieu
Date
2010-02-24 06:00:19 -0600 (Wed, 24 Feb 2010)

Log Message

Skinny: Milestone 0: avoid crash when closing sockets by using mutexes

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c (16765 => 16766)


--- freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c	2010-02-24 12:00:11 UTC (rev 16765)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c	2010-02-24 12:00:19 UTC (rev 16766)
@@ -1559,26 +1559,22 @@
 }
 
 
-static void close_socket(switch_socket_t **sock)
+static void close_socket(switch_socket_t **sock, skinny_profile_t *profile)
 {
-	/* TODO
 	switch_mutex_lock(profile->sock_mutex);
-	*/
 	if (*sock) {
 		switch_socket_shutdown(*sock, SWITCH_SHUTDOWN_READWRITE);
 		switch_socket_close(*sock);
 		*sock = NULL;
 	}
-	/* TODO
 	switch_mutex_unlock(profile->sock_mutex);
-	*/
 }
 
 static switch_status_t kill_listener(listener_t *listener, void *pvt)
 {
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Killing listener.\n");
 	switch_clear_flag(listener, LFLAG_RUNNING);
-	close_socket(&listener->sock);
+	close_socket(&listener->sock, listener->profile);
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -1684,7 +1680,7 @@
 	}
 	
 	if (listener->sock) {
-		close_socket(&listener->sock);
+		close_socket(&listener->sock, profile);
 	}
 
 	switch_thread_rwlock_unlock(listener->rwlock);
@@ -1808,7 +1804,7 @@
 
  end:
 
-	close_socket(&profile->sock);
+	close_socket(&profile->sock, profile);
 	
 	if (pool) {
 		switch_core_destroy_memory_pool(&pool);
@@ -2218,7 +2214,7 @@
 		switch_hash_this(hi, NULL, NULL, &val);
 		profile = (skinny_profile_t *) val;
 
-		close_socket(&profile->sock);
+		close_socket(&profile->sock, profile);
 
 		while (profile->listener_threads) {
 			switch_yield(100000);