[svn-commits] mmichelson: branch mmichelson/pool_shark2 r381817 - in /team/mmichelson/pool_...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Feb 19 21:41:18 CST 2013


Author: mmichelson
Date: Tue Feb 19 21:41:14 2013
New Revision: 381817

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381817
Log:
Streamline the process for new session creation.

On incoming out-of-dialog INVITEs, the on_rx_request()
callback is now called in our threadpool. This means there is
no reason to push the handling of the INVITE to the threadpool.
Now we just handle it in-line. This means that there is no good
reason to pass a serializer into ast_sip_session_alloc(). Instead,
the session can just create its own serializer during allocation.

I also changed the behavior of ast_sip_session_alloc() to increase
the refcount of the passed-in endpoint by one since it is keeping
a reference to the endpoint. This leads to much cleaner code that
calls ast_sip_session_alloc() since it can always unconditionally
unref its local endpoint.

With these two changes in place, the somewhat awkward destroy_serializer
and destroy_endpoint booleans are now gone from incoming INVITE
handling.


Modified:
    team/mmichelson/pool_shark2/channels/chan_gulp.c
    team/mmichelson/pool_shark2/include/asterisk/res_sip_session.h
    team/mmichelson/pool_shark2/res/res_sip_session.c

Modified: team/mmichelson/pool_shark2/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/channels/chan_gulp.c?view=diff&rev=381817&r1=381816&r2=381817
==============================================================================
--- team/mmichelson/pool_shark2/channels/chan_gulp.c (original)
+++ team/mmichelson/pool_shark2/channels/chan_gulp.c Tue Feb 19 21:41:14 2013
@@ -647,14 +647,13 @@
 
 struct request_data {
 	struct ast_sip_session *session;
-	struct ast_taskprocessor *serializer;
 	const char *dest;
 };
 
 static int request(void *obj)
 {
 	struct request_data *req_data = obj;
-	struct ast_sip_endpoint *endpoint = ast_sip_endpoint_alloc("constant");
+	RAII_VAR(struct ast_sip_endpoint *, endpoint, ast_sip_endpoint_alloc("constant"), ao2_cleanup);
 	struct ast_sip_session *session = NULL;
 
 	if (!endpoint) {
@@ -667,7 +666,7 @@
 	endpoint->min_se = 90;
 	endpoint->sess_expires = 1800;
 
-	if (!(session = ast_sip_session_create_outgoing(endpoint, req_data->dest, req_data->serializer))) {
+	if (!(session = ast_sip_session_create_outgoing(endpoint, req_data->dest))) {
 		return -1;
 	}
 
@@ -678,18 +677,12 @@
 /*! \brief Function called by core to create a new outgoing Gulp session */
 static struct ast_channel *gulp_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *data, int *cause)
 {
-	struct ast_taskprocessor *serializer = ast_sip_create_serializer();
 	struct request_data req_data;
 	struct ast_sip_session *session;
-	if (!serializer) {
-		return NULL;
-	}
 
 	req_data.dest = data;
-	req_data.serializer = serializer;
-
-	if (ast_sip_push_task_synchronous(serializer, request, &req_data)) {
-		ast_taskprocessor_unreference(serializer);
+
+	if (ast_sip_push_task_synchronous(NULL, request, &req_data)) {
 		return NULL;
 	}
 

Modified: team/mmichelson/pool_shark2/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/include/asterisk/res_sip_session.h?view=diff&rev=381817&r1=381816&r2=381817
==============================================================================
--- team/mmichelson/pool_shark2/include/asterisk/res_sip_session.h (original)
+++ team/mmichelson/pool_shark2/include/asterisk/res_sip_session.h Tue Feb 19 21:41:14 2013
@@ -215,18 +215,16 @@
  * as placing all registered supplements onto the session.
  * \param endpoint The endpoint that this session communicates with
  * \param inv_session The PJSIP INVITE session data
- * \param serializer SIP task queue to use for this session. May be NULL.
- */
-struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint, pjsip_inv_session *inv, struct ast_taskprocessor *serializer);
+ */
+struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint, pjsip_inv_session *inv);
 
 /*!
  * \brief Create a new outgoing SIP session
  *
  * \param endpoint The endpoint that this session uses for settings
  * \param uri The URI to call
- * \param serializer SIP task queue to use for this session. May be NULL.
- */
-struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint *endpoint, const char *uri, struct ast_taskprocessor *serializer);
+ */
+struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint *endpoint, const char *uri);
 
 /*!
  * \brief Register an SDP handler

Modified: team/mmichelson/pool_shark2/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/res/res_sip_session.c?view=diff&rev=381817&r1=381816&r2=381817
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip_session.c (original)
+++ team/mmichelson/pool_shark2/res/res_sip_session.c Tue Feb 19 21:41:14 2013
@@ -486,7 +486,7 @@
 	return 0;
 }
 
-struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint, pjsip_inv_session *inv_session, struct ast_taskprocessor *serializer)
+struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint, pjsip_inv_session *inv_session)
 {
 	RAII_VAR(struct ast_sip_session *, session, ao2_alloc(sizeof(*session), session_destructor), ao2_cleanup);
 	struct ast_sip_session_supplement *iter;
@@ -498,14 +498,11 @@
 	if (!session->datastores) {
 		return NULL;
 	}
-	if (serializer) {
-		session->serializer = serializer;
-	} else {
-		session->serializer = ast_sip_create_serializer();
-	}
+	session->serializer = ast_sip_create_serializer();
 	if (!session->serializer) {
 		return NULL;
 	}
+	ao2_ref(endpoint, +1);
 	session->endpoint = endpoint;
 	session->inv_session = inv_session;
 	if (add_supplements(session)) {
@@ -584,7 +581,7 @@
 	return 0;
 }
 
-struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint *endpoint, const char *uri, struct ast_taskprocessor *serializer)
+struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint *endpoint, const char *uri)
 {
 	pj_str_t local_uri = pj_str("sip:temp at localhost"), remote_uri = pj_str((char*)uri);
 	pjsip_dialog *dlg = NULL;
@@ -646,7 +643,7 @@
 		return NULL;
 	}
 
-	if (!(session = ast_sip_session_alloc(endpoint, inv_session, serializer))) {
+	if (!(session = ast_sip_session_alloc(endpoint, inv_session))) {
 		pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
 		return NULL;
 	}
@@ -733,83 +730,36 @@
 	return inv_session;
 }
 
-struct new_request_data {
-	pjsip_rx_data *rdata;
-	struct ast_taskprocessor *serializer;
-	struct ast_sip_endpoint *endpoint;
-};
-
-static struct new_request_data *new_request_data_alloc(pjsip_rx_data *rdata)
-{
-	struct new_request_data *nrd = ast_calloc(1, sizeof(*nrd));
-	if (!nrd) {
-		return NULL;
-	}
-	pjsip_rx_data_clone(rdata, 0, &nrd->rdata);
-	if (!nrd->rdata) {
-		ast_free(nrd);
-		return NULL;
-	}
-	nrd->serializer = ast_sip_create_serializer();
-	if (!nrd->serializer) {
-		pjsip_rx_data_free_cloned(nrd->rdata);
-		ast_free(nrd);
-		return NULL;
-	}
-	nrd->endpoint = ast_pjsip_rdata_get_endpoint(rdata);
-	return nrd;
-}
-
-static int handle_new_invite_request(void *data)
-{
-	/* The goal here is to create a task and throw it into
-	 * the threadpool. The threadpool callback will deal with
-	 * actually creating a new session and all the other bells
-	 * and whistles. Since threadpool support is not in this
-	 * branch at this point, we'll just handle this in PJSIP's
-	 * endpoint thread.
-	 */
-	struct new_request_data *nrd = data;
-	pjsip_rx_data *rdata = nrd->rdata;
-	struct ast_taskprocessor *serializer = nrd->serializer;
+static void handle_new_invite_request(pjsip_rx_data *rdata)
+{
+	RAII_VAR(struct ast_sip_endpoint *, endpoint,
+			ast_pjsip_rdata_get_endpoint(rdata), ao2_cleanup);
 	pjsip_tx_data *tdata = NULL;
 	pjsip_inv_session *inv_session = NULL;
-	struct ast_sip_endpoint *endpoint = nrd->endpoint;
 	struct ast_sip_session *session = NULL;
 	pjsip_timer_setting timer;
 	pjsip_rdata_sdp_info *sdp_info;
 	pjmedia_sdp_session *local = NULL;
-	int destroy_serializer = 1;
-	int destroy_endpoint = 1;
-
-	endpoint = ast_pjsip_rdata_get_endpoint(rdata);
-	ast_assert(endpoint != NULL);
 
 	inv_session = pre_session_setup(rdata, endpoint);
 	if (!inv_session) {
 		/* pre_session_setup() returns a response on failure */
-		goto end;
-	}
-
-	session = ast_sip_session_alloc(endpoint, inv_session, serializer);
+		return;
+	}
+
+	session = ast_sip_session_alloc(endpoint, inv_session);
 	if (!session) {
 		if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) {
 			pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
 		} else {
 			pjsip_inv_send_msg(inv_session, tdata);
 		}
-		goto end;
+		return;
 	}
 	
 	/* From this point on, any calls to pjsip_inv_terminate have the last argument as PJ_TRUE
 	 * so that we will be notified so we can destroy the session properly
-	 *
-	 * Also from this point on, the serializer and endpoint belong to the session, so
-	 * there is no need to destroy them ourselves. When the session dies, so will the
-	 * serializer and endpoint.
 	 */
-	destroy_serializer = 0;
-	destroy_endpoint = 0;
 
 	switch (get_destination(session, rdata)) {
 	case SIP_GET_DEST_EXTEN_FOUND:
@@ -821,7 +771,7 @@
 		} else  {
 			pjsip_inv_terminate(inv_session, 416, PJ_TRUE);
 		}
-		goto end;
+		return;
 	case SIP_GET_DEST_EXTEN_NOT_FOUND:
 	case SIP_GET_DEST_EXTEN_PARTIAL:
 	default:
@@ -830,7 +780,7 @@
 		} else  {
 			pjsip_inv_terminate(inv_session, 404, PJ_TRUE);
 		}
-		goto end;
+		return;
 	};
 
 	if ((sdp_info = pjsip_rdata_get_sdp_info(rdata)) && (sdp_info->sdp_err == PJ_SUCCESS)) {
@@ -840,7 +790,7 @@
 			} else  {
 				pjsip_inv_terminate(inv_session, 500, PJ_TRUE);
 			}
-			goto end;
+			return;
 		}
 		/* We are creating a local SDP which is an answer to their offer */
 		local = create_local_sdp(inv_session, session, sdp_info->sdp);
@@ -856,7 +806,7 @@
 		} else  {
 			pjsip_inv_terminate(inv_session, 500, PJ_TRUE);
 		}
-		goto end;
+		return;
 	} else {
 		pjsip_inv_set_local_sdp(inv_session, local);
 	}
@@ -869,22 +819,11 @@
 	/* At this point, we've verified what we can, so let's go ahead and send a 100 Trying out */
 	if (pjsip_inv_initial_answer(inv_session, rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS) {
 		pjsip_inv_terminate(inv_session, 500, PJ_TRUE);
-		goto end;
+		return;
 	}
 	ast_sip_session_send_response(session, tdata);
 
 	handle_incoming_request(session, rdata);
-
-end:
-	if (destroy_serializer) {
-		ast_taskprocessor_unreference(serializer);
-	}
-	if (destroy_endpoint) {
-		ao2_cleanup(endpoint);
-	}
-	pjsip_rx_data_free_cloned(rdata);
-	ast_free(nrd);
-	return 0;
 }
 /*!
  * \brief Called when a new SIP request comes into PJSIP
@@ -904,7 +843,6 @@
  */
 static pj_bool_t session_on_rx_request(pjsip_rx_data *rdata)
 { 
-	struct new_request_data *nrd;
 	pj_status_t handled = PJ_FALSE;
 	pjsip_dialog *dlg = pjsip_rdata_get_dlg(rdata);
 
@@ -915,20 +853,7 @@
 			break;
 		}
 		handled = PJ_TRUE;
-
-		nrd = new_request_data_alloc(rdata);
-		if (!nrd) {
-			pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
-			break;
-		}
-		if (ast_sip_push_task(nrd->serializer, handle_new_invite_request, nrd)) {
-			ast_log(LOG_WARNING, "Failed to pass new INVITE to the threadpool\n");
-			pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
-			pjsip_rx_data_free_cloned(nrd->rdata);
-			ast_taskprocessor_unreference(nrd->serializer);
-			ao2_cleanup(nrd->endpoint);
-			ast_free(nrd);
-		}
+		handle_new_invite_request(rdata);
 		break;
 	case PJSIP_OTHER_METHOD:
 		/* Area for INFO and REFER, possibly other methods */




More information about the svn-commits mailing list