[asterisk-commits] file: branch file/netsock2 r95442 - /team/file/netsock2/main/netsock2.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 31 12:38:16 CST 2007


Author: file
Date: Mon Dec 31 12:38:16 2007
New Revision: 95442

URL: http://svn.digium.com/view/asterisk?view=rev&rev=95442
Log:
Fix up socket list destruction for SCTP and UDP sockets. TCP and TLS sockets are going to take more work since they operate in their own thread.

Modified:
    team/file/netsock2/main/netsock2.c

Modified: team/file/netsock2/main/netsock2.c
URL: http://svn.digium.com/view/asterisk/team/file/netsock2/main/netsock2.c?view=diff&rev=95442&r1=95441&r2=95442
==============================================================================
--- team/file/netsock2/main/netsock2.c (original)
+++ team/file/netsock2/main/netsock2.c Mon Dec 31 12:38:16 2007
@@ -181,7 +181,7 @@
 		child_socket->addr.len = acceptaddrlen;
 
 		/* Now as the last step... create the thread that will handle this socket */
-		if (ast_pthread_create_detached_background(&child_socket->thread, NULL, netsock2_accept_thread, child_socket)) {
+		if (ast_pthread_create_background(&child_socket->thread, NULL, netsock2_accept_thread, child_socket)) {
 			/* TODO: Print out a warning message or something */
 			ast_free(child_socket);
 			close(netsocket);
@@ -249,12 +249,20 @@
 				pthread_join(child_thread, NULL);
 				ast_debug(1, "Child socket thread for %p has been stopped\n", child_socket);
 			}
+		} else {
+			/* Other transports do not have their own thread so we can destroy them here */
+			close(socket->fd);
+			ast_free(socket);
 		}
 	}
 
 	/* Drop the I/O context */
-
-	return -1;
+	io_context_destroy(socket_list->ioc);
+
+	/* Free ourselves, all is done */
+	ast_free(socket_list);
+
+	return 0;
 }
 
 /*! Internal function that converts from transport to socket type */
@@ -495,7 +503,7 @@
 
 	/* If this is the first socket in the list create a new thread to handle everything */
 	if (socket_list->thread == AST_PTHREADT_NULL) {
-		if (ast_pthread_create_detached_background(&socket_list->thread, NULL, netsock2_main_thread, socket_list)) {
+		if (ast_pthread_create_background(&socket_list->thread, NULL, netsock2_main_thread, socket_list)) {
 			ast_log(LOG_ERROR, "Failed to create main thread for socket list %p, bollocks.\n", socket_list);
 			/* TODO: Remove everything and free it */
 			return -1;




More information about the asterisk-commits mailing list