[asterisk-commits] mmichelson: branch mmichelson/pool_shark r380252 - /team/mmichelson/pool_shar...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 28 13:54:26 CST 2013


Author: mmichelson
Date: Mon Jan 28 13:54:22 2013
New Revision: 380252

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380252
Log:
Handle incoming mid-dialog requests/responses in the threadpool.

This also places session-ending logic in the threadpool.


Modified:
    team/mmichelson/pool_shark/res/res_sip_session.c

Modified: team/mmichelson/pool_shark/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark/res/res_sip_session.c?view=diff&rev=380252&r1=380251&r2=380252
==============================================================================
--- team/mmichelson/pool_shark/res/res_sip_session.c (original)
+++ team/mmichelson/pool_shark/res/res_sip_session.c Mon Jan 28 13:54:22 2013
@@ -44,7 +44,7 @@
 /* Some forward declarations */
 static void handle_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata);
 static void handle_incoming_response(struct ast_sip_session *session, pjsip_rx_data *rdata);
-static void handle_incoming(struct ast_sip_session *session, pjsip_rx_data *rdata);
+static int handle_incoming(void *data);
 static void handle_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata);
 static void handle_outgoing_response(struct ast_sip_session *session, pjsip_tx_data *tdata);
 static void handle_outgoing(struct ast_sip_session *session, pjsip_tx_data *tdata);
@@ -915,8 +915,42 @@
 	}
 }
 
-static void handle_incoming(struct ast_sip_session *session, pjsip_rx_data *rdata)
-{
+struct handle_incoming_data {
+	struct ast_sip_session *session;
+	pjsip_rx_data *rdata;
+};
+
+static void handle_incoming_data_destroy(void *obj)
+{
+	struct handle_incoming_data *hid = obj;
+	if (hid->rdata) {
+		pjsip_rx_data_free_cloned(hid->rdata);
+	}
+	if (hid->session) {
+		ao2_ref(hid->session, -1);
+	}
+}
+
+static struct handle_incoming_data *handle_incoming_data_alloc(struct ast_sip_session *session, pjsip_rx_data *rdata)
+{
+	struct handle_incoming_data *hid = ao2_alloc(sizeof(*hid), handle_incoming_data_destroy);
+	if (!hid) {
+		return NULL;
+	}
+	if (pjsip_rx_data_clone(rdata, 0, &hid->rdata) != PJ_SUCCESS) {
+		ao2_ref(hid, -1);
+		return NULL;
+	}
+	ao2_ref(session, +1);
+	hid->session = session;
+	return hid;
+}
+
+static int handle_incoming(void *data)
+{
+	struct handle_incoming_data *hid = data;
+	struct ast_sip_session *session = hid->session;
+	pjsip_rx_data *rdata = hid->rdata;
 	ast_debug(3, "Received %s\n", rdata->msg_info.msg->type == PJSIP_REQUEST_MSG ?
 			"request" : "response");
 	if (rdata->msg_info.msg->type == PJSIP_REQUEST_MSG) {
@@ -924,6 +958,8 @@
 	} else {
 		handle_incoming_response(session, rdata);
 	}
+	ao2_ref(hid, -1);
+	return 0;
 }
 
 static void handle_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
@@ -973,9 +1009,27 @@
 	}
 }
 
+static int session_end(void *data)
+{
+	struct ast_sip_session *session = data;
+	struct ast_sip_session_supplement *iter;
+
+	/* Session is dead. Let's get rid of the reference to the session */
+	AST_LIST_TRAVERSE(&session->supplements, iter, next) {
+		if (iter->session_end) {
+			iter->session_end(session);
+		}
+	}
+
+	session->inv_session->mod_data[session_module.id] = NULL;
+	ao2_cleanup(session);
+	return 0;
+}
+
 static void session_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e)
 {
 	struct ast_sip_session *session = inv->mod_data[session_module.id];
+	struct handle_incoming_data *hid;
 	ast_debug(3, "on_state_changed callback called. Event dump to follow\n");
 	ast_debug(3, "inv state is %s, event type is %s\n", pjsip_inv_state_name(inv->state), pjsip_event_str(e->type));
 	switch(e->type) {
@@ -983,7 +1037,10 @@
 		handle_outgoing(session, e->body.tx_msg.tdata);
 		break;
 	case PJSIP_EVENT_RX_MSG:
-		handle_incoming(session, e->body.rx_msg.rdata);
+		hid = handle_incoming_data_alloc(session, e->body.rx_msg.rdata);
+		if (hid) {
+			ast_sip_push_task(session->work, handle_incoming, hid);
+		}
 		break;
 	case PJSIP_EVENT_TSX_STATE:
 		ast_debug(3, "Source of transaction state change is %s\n", pjsip_event_str(e->body.tsx_state.type));
@@ -993,7 +1050,10 @@
 			handle_outgoing(session, e->body.tsx_state.src.tdata);
 			break;
 		case PJSIP_EVENT_RX_MSG:
-			handle_incoming(session, e->body.tsx_state.src.rdata);
+			hid = handle_incoming_data_alloc(session, e->body.tsx_state.src.rdata);
+			if (hid) {
+				ast_sip_push_task(session->work, handle_incoming, hid);
+			}
 			break;
 		case PJSIP_EVENT_TRANSPORT_ERROR:
 		case PJSIP_EVENT_TIMER:
@@ -1013,17 +1073,7 @@
 	}
 
 	if (inv->state == PJSIP_INV_STATE_DISCONNECTED) {
-		struct ast_sip_session_supplement *iter;
-
-		/* Session is dead. Let's get rid of the reference to the session */
-		AST_LIST_TRAVERSE(&session->supplements, iter, next) {
-			if (iter->session_end) {
-				iter->session_end(session);
-			}
-		}
-
-		inv->mod_data[session_module.id] = NULL;
-		ao2_cleanup(session);
+		ast_sip_push_task(session->work, session_end, session);
 	}
 }
 




More information about the asterisk-commits mailing list