[svn-commits] dvossel: branch dvossel/sip_nonblocking_tcp_client r220152 - /team/dvossel/si...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Sep 24 10:30:23 CDT 2009


Author: dvossel
Date: Thu Sep 24 10:30:19 2009
New Revision: 220152

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=220152
Log:
sip_threadinfo objects are now created and linked into the threadl table
before tcp_helper_thread creation for clients.  This allows for the
alert_pipe to be set up before the thread is started.  Servers still create
the sip_threadinfo object within the tcp_helper_thread, but we are
guaranteed no writing will be done until the alert_pipe is up because the
helper thread has not yet handed the tcptls_session of to a dialog.


Modified:
    team/dvossel/sip_nonblocking_tcp_client/channels/chan_sip.c

Modified: team/dvossel/sip_nonblocking_tcp_client/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/sip_nonblocking_tcp_client/channels/chan_sip.c?view=diff&rev=220152&r1=220151&r2=220152
==============================================================================
--- team/dvossel/sip_nonblocking_tcp_client/channels/chan_sip.c (original)
+++ team/dvossel/sip_nonblocking_tcp_client/channels/chan_sip.c Thu Sep 24 10:30:19 2009
@@ -2897,6 +2897,25 @@
 	return _sip_tcp_helper_thread(NULL, tcptls_session);
 }
 
+static struct sip_threadinfo *sip_threadinfo_create(struct ast_tcptls_session_instance *tcptls_session)
+{
+	struct sip_threadinfo *th;
+	th = ao2_alloc(sizeof(*th), NULL);
+
+	if (!th)
+		return NULL;
+
+	th->tcptls_session = tcptls_session;
+	if (tcptls_session->ssl)
+		th->type = SIP_TRANSPORT_TLS;
+	else
+		th->type = SIP_TRANSPORT_TCP;
+//todohere create alert pipe!
+	ao2_t_link(threadl, th, "Adding new tcptls helper thread");
+
+	return th;
+}
+
 /*! \brief SIP TCP thread management function
 	This function reads from the socket, parses the packet into a request
 */
@@ -2907,21 +2926,30 @@
 	struct sip_threadinfo *me;
 	char buf[1024] = "";
 
-	me = ao2_alloc(sizeof(*me), NULL);
-
-	if (!me)
+	/* If this is a server connection, create a new thread info object.
+	 * 
+	 * else if this is a client connection, we have already created a thread info
+	 * object and linked it to the threadl container, find it.
+	 *
+	 * A threadinfo object has 2 references once it is created, one for the table, and one for this thread.
+	 */
+	if (!tcptls_session->client) {
+		me = sip_threadinfo_create(tcptls_session);
+	} else {
+		struct sip_threadinfo tmp = {
+			.tcptls_session = tcptls_session,
+		};
+		if ((me = ao2_t_find(threadl, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread"))) {
+			ao2_t_ref(me, -1, "In tcp_helper_thread, unref threadinfo object after finding it");
+		}
+	}
+
+	if (!me) {
 		goto cleanup2;
+	}
 
 	me->threadid = pthread_self();
-	me->tcptls_session = tcptls_session;
-	if (tcptls_session->ssl)
-		me->type = SIP_TRANSPORT_TLS;
-	else
-		me->type = SIP_TRANSPORT_TCP;
-
 	ast_debug(2, "Starting thread for %s server\n", tcptls_session->ssl ? "SSL" : "TCP");
-
-	ao2_t_link(threadl, me, "Adding new tcptls helper thread");
 
 	if (!(req.data = ast_str_create(SIP_MIN_PACKET)))
 		goto cleanup;
@@ -22614,6 +22642,7 @@
 {
 	struct sip_socket *s = &p->socket;
 	static const char name[] = "SIP socket";
+	struct sip_threadinfo *th;
 	struct ast_tcptls_session_instance *tcptls_session;
 	struct ast_tcptls_session_args ca = {
 		.name = name,
@@ -22674,14 +22703,26 @@
 
 	s->fd = ca.accept_fd;
 
+	/* client connections need to have the sip_threadinfo object created before
+	 * the thread is detached.  This ensures the alert_pipe is up before it will
+	 * be used.  Note that this function links the new threadinfo object into the
+	 * threadl container. */
+	if (!(th = sip_threadinfo_create(s->tcptls_session))) {
+		close(ca.accept_fd);
+		s->fd = ca.accept_fd = -1;
+		return -1;
+	}
+
 	/* Give the new thread a reference */
 	ao2_ref(s->tcptls_session, +1);
 
 	if (ast_pthread_create_background(&ca.master, NULL, sip_tcp_worker_fn, s->tcptls_session)) {
 		ast_debug(1, "Unable to launch '%s'.", ca.name);
+		ao2_t_unlink(threadl, th, "Removing tcptls thread info object, thread failed to open");
 		ao2_ref(s->tcptls_session, -1);
 		close(ca.accept_fd);
 		s->fd = ca.accept_fd = -1;
+		return -1;
 	}
 
 	return s->fd;




More information about the svn-commits mailing list