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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 9 16:01:11 CST 2008


Author: file
Date: Wed Jan  9 16:01:10 2008
New Revision: 97637

URL: http://svn.digium.com/view/asterisk?view=rev&rev=97637
Log:
Protect the list of child sockets with a lock.

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=97637&r1=97636&r2=97637
==============================================================================
--- team/file/netsock2/main/netsock2.c (original)
+++ team/file/netsock2/main/netsock2.c Wed Jan  9 16:01:10 2008
@@ -78,7 +78,7 @@
 #endif
 	int references;
 	AST_LIST_ENTRY(ast_netsock2_socket) list;
-	AST_LIST_HEAD_NOLOCK(, ast_netsock2_socket) child_sockets;
+	AST_LIST_HEAD(, ast_netsock2_socket) child_sockets;
 };
 
 struct ast_netsock2_socket_list {
@@ -161,7 +161,9 @@
 	ast_debug(1, "Removing child socket %p from parent socket %p list and closing/freeing\n", child_socket, parent);
 
 	/* It is our responsibility to remove ourselves from the parent, nobody else will do it */
+	AST_LIST_LOCK(&parent->child_sockets);
 	AST_LIST_REMOVE(&parent->child_sockets, child_socket, list);
+	AST_LIST_UNLOCK(&parent->child_sockets);
 
 	/* Close out the actual socket */
 	close(child_socket->fd);
@@ -216,7 +218,9 @@
 		}
 
 		/* All is well... add it to this parent socket's list of child sockets */
+		AST_LIST_LOCK(&socket->child_sockets);
 		AST_LIST_INSERT_TAIL(&socket->child_sockets, child_socket, list);
+		AST_LIST_UNLOCK(&socket->child_sockets);
 	}
 
 	return 1;
@@ -505,6 +509,8 @@
 		if (transport == AST_NETSOCK2_TRANSPORT_TCP || transport == AST_NETSOCK2_TRANSPORT_TLS) {
 			int flags = fcntl(netsocket, F_GETFL);
 			fcntl(netsocket, F_SETFL, flags | O_NONBLOCK);
+			/* Initialize the list that will hold our child sockets */
+			AST_LIST_HEAD_INIT(&netsock2_socket->child_sockets);
 		}
 #ifdef HAVE_OPENSSL
 		/* Setup TLS and OpenSSL parameters */




More information about the asterisk-commits mailing list