Browse Source

- more callback fixes (TMCB_E2E_CANCEL_IN never called after the latest
changes)
- some minor optimizations attempts (predict all the callback branches/ifs as
not taken since in the normal case we don't have any callbacks)

Andrei Pelinescu-Onciul 18 years ago
parent
commit
66298eb439
5 changed files with 41 additions and 29 deletions
  1. 6 3
      modules/tm/t_fwd.c
  2. 2 4
      modules/tm/t_hooks.c
  3. 5 1
      modules/tm/t_hooks.h
  4. 23 17
      modules/tm/t_lookup.c
  5. 5 4
      modules/tm/t_reply.c

+ 6 - 3
modules/tm/t_fwd.c

@@ -473,13 +473,16 @@ void e2e_cancel( struct sip_msg *cancel_msg,
 	int i;
 	int lowest_error;
 	int ret;
+	struct tmcb_params tmcb;
 
 	cancel_bm=0;
 	lowest_error=0;
 
-	if (unlikely(has_tran_tmcbs(t_invite, TMCB_E2ECANCEL_IN)))
-		run_trans_callbacks( TMCB_E2ECANCEL_IN, t_cancel, cancel_msg, 0,
-								cancel_msg->REQ_METHOD);
+	if (unlikely(has_tran_tmcbs(t_invite, TMCB_E2ECANCEL_IN))){
+		INIT_TMCB_PARAMS(tmcb, cancel_msg, 0, cancel_msg->REQ_METHOD);
+		run_trans_callbacks_internal(&t_invite->tmcb_hl, TMCB_E2ECANCEL_IN, 
+										t_cancel, &tmcb);
+	}
 	/* first check if there are any branches */
 	if (t_invite->nr_of_outgoings==0){
 		t_invite->flags|=T_CANCELED;

+ 2 - 4
modules/tm/t_hooks.c

@@ -288,16 +288,14 @@ void run_onsend_callbacks(int type, struct retr_buf* rbuf,
 }
 
 
-void run_onsend_callbacks2(int type , struct tmcb_params* p)
+void run_onsend_callbacks2(int type, struct cell* trans, struct tmcb_params* p)
 {
-	struct cell * trans;
 
 	if (p->t_rbuf==0) return;
-	trans=p->t_rbuf->my_T;
 	if ( trans==0 || trans->tmcb_hl.first==0 || 
 			((trans->tmcb_hl.reg_types)&type)==0 )
 		return;
-	run_trans_callbacks_internal(&trans->tmcb_hl, type, trans, p);
+	run_trans_callbacks_internal(&trans->tmcb_hl, type, p->t_rbuf->my_T, p);
 }
 
 #endif

+ 5 - 1
modules/tm/t_hooks.h

@@ -153,6 +153,10 @@ struct cell;
  * TMCB_RESPONSE_IN -- a brand-new reply was received which matches
  * an existing non-local transaction. It may or may not be a retransmission.
  * No lock is held here (yet).
+ * Note: for an invite transaction this callback will also catch the reply
+ *  to local cancels (e.g. branch canceled due to fr_inv_timeout). To
+ *  distinguish between the two, one would need to look at the method in
+ *  Cseq (look at t_reply.c:1630 (reply_received()) for an example).
  * It's unsafe to register other TMCB callbacks.
  *
  *  TMCB_RESPONSE_OUT -- a final reply was sent out (either local
@@ -430,7 +434,7 @@ void run_local_reqin_callbacks( struct cell *trans, struct sip_msg *req,
 
 void run_onsend_callbacks(int type, struct retr_buf* rbuf, struct sip_msg* req,
 									struct sip_msg* repl, short flags);
-void run_onsend_callbacks2(int type, struct tmcb_params* p);
+void run_onsend_callbacks2(int type, struct cell* t, struct tmcb_params* p);
 #endif
 
 #endif

+ 23 - 17
modules/tm/t_lookup.c

@@ -96,6 +96,7 @@
 
 
 #include "../../comp_defs.h"
+#include "../../compiler_opt.h"
 #include "../../dprint.h"
 #include "../../config.h"
 #include "../../parser/parser_f.h"
@@ -886,22 +887,25 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
 		 * enabled -- except callback customers, nobody cares about 
 		 * retransmissions of multiple 200/INV or ACK/200s
 		 */
-		if (is_invite(p_cell) && p_msg->REPLY_STATUS>=200 
-		&& p_msg->REPLY_STATUS<300 
-		&& ( (!is_local(p_cell) &&
-				has_tran_tmcbs(p_cell,TMCB_RESPONSE_OUT|TMCB_E2EACK_IN) )
-			|| (is_local(p_cell)&&has_tran_tmcbs(p_cell,TMCB_LOCAL_COMPLETED))
-		)) {
+		if (unlikely( is_invite(p_cell) && p_msg->REPLY_STATUS>=200 
+			&& p_msg->REPLY_STATUS<300 
+			&& ((!is_local(p_cell) &&
+				has_tran_tmcbs(p_cell, TMCB_RESPONSE_OUT|TMCB_E2EACK_IN) )
+			|| (is_local(p_cell)&&has_tran_tmcbs(p_cell, TMCB_LOCAL_COMPLETED))
+		)) ) {
 			if (parse_headers(p_msg, HDR_TO_F, 0)==-1) {
 				LOG(L_ERR, "ERROR: t_reply_matching: to parsing failed\n");
 			}
 		}
-		if (!is_local(p_cell)) {
-			run_trans_callbacks( TMCB_RESPONSE_IN, T, T->uas.request, p_msg,
-				p_msg->REPLY_STATUS);
-		}else{
-			run_trans_callbacks( TMCB_LOCAL_RESPONSE_IN, T, T->uas.request, 
-					p_msg, p_msg->REPLY_STATUS);
+		if (unlikely(has_tran_tmcbs(T, TMCB_RESPONSE_IN |
+										TMCB_LOCAL_RESPONSE_IN))){
+			if (!is_local(p_cell)) {
+				run_trans_callbacks( TMCB_RESPONSE_IN, T, T->uas.request,
+										p_msg, p_msg->REPLY_STATUS);
+			}else{
+				run_trans_callbacks( TMCB_LOCAL_RESPONSE_IN, T, T->uas.request,
+										p_msg, p_msg->REPLY_STATUS);
+			}
 		}
 		return 1;
 	} /* for cycle */
@@ -1198,12 +1202,14 @@ int t_newtran( struct sip_msg* p_msg )
 	/* transaction found, it's a retransmission  */
 	if (lret>0) {
 		if (p_msg->REQ_METHOD==METHOD_ACK) {
-			run_trans_callbacks(TMCB_ACK_NEG_IN, T, p_msg, 0, 
-									p_msg->REQ_METHOD);
+			if (unlikely(has_tran_tmcbs(T, TMCB_ACK_NEG_IN)))
+				run_trans_callbacks(TMCB_ACK_NEG_IN, T, p_msg, 0, 
+										p_msg->REQ_METHOD);
 			t_release_transaction(T);
 		} else {
-			run_trans_callbacks(TMCB_REQ_RETR_IN, T, p_msg, 0,
-									p_msg->REQ_METHOD);
+			if (unlikely(has_tran_tmcbs(T, TMCB_REQ_RETR_IN)))
+				run_trans_callbacks(TMCB_REQ_RETR_IN, T, p_msg, 0,
+										p_msg->REQ_METHOD);
 			t_retransmit_reply(T);
 		}
 		/* things are done -- return from script */
@@ -1214,7 +1220,7 @@ int t_newtran( struct sip_msg* p_msg )
 
 	if (lret==-2) { /* was it an e2e ACK ? if so, trigger a callback */
 		/* no callbacks? complete quickly */
-		if ( !has_tran_tmcbs(t_ack,TMCB_E2EACK_IN) ) {
+		if (likely( !has_tran_tmcbs(t_ack,TMCB_E2EACK_IN) )) {
 			UNLOCK_HASH(p_msg->hash_index);
 			return 1;
 		} 

+ 5 - 4
modules/tm/t_reply.c

@@ -501,7 +501,8 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len,
 			if (unlikely(has_tran_tmcbs(trans, TMCB_RESPONSE_SENT))){
 				INIT_TMCB_ONSEND_PARAMS(onsend_params, 0, 0, rb, &rb->dst, 
 								buf, len, TMCB_LOCAL_F, rb->branch, code);
-				run_onsend_callbacks2(TMCB_RESPONSE_SENT, &onsend_params);
+				run_onsend_callbacks2(TMCB_RESPONSE_SENT, trans,
+										&onsend_params);
 			}
 #else
 		SEND_PR_BUFFER( rb, buf, len );
@@ -1466,7 +1467,7 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
 									res_len,
 									(relayed_msg==FAKED_REPLY)?TMCB_LOCAL_F:0,
 									uas_rb->branch, relayed_code);
-				run_onsend_callbacks2(TMCB_RESPONSE_SENT, &onsend_params);
+				run_onsend_callbacks2(TMCB_RESPONSE_SENT, t, &onsend_params);
 			}
 #endif
 		}
@@ -1657,7 +1658,7 @@ int reply_received( struct sip_msg  *p_msg )
 									t->uas.request, p_msg, &uac->request,
 									&uac->request.dst, ack, ack_len,
 									TMCB_LOCAL_F, branch, TYPE_LOCAL_ACK);
-							run_onsend_callbacks2(TMCB_REQUEST_SENT,
+							run_onsend_callbacks2(TMCB_REQUEST_SENT, t,
 													&onsend_params);
 						}
 #else
@@ -1676,7 +1677,7 @@ int reply_received( struct sip_msg  *p_msg )
 									t->uas.request, p_msg, &uac->request,
 									&lack_dst, ack, ack_len, TMCB_LOCAL_F,
 									branch, TYPE_LOCAL_ACK);
-							run_onsend_callbacks2(TMCB_REQUEST_SENT,
+							run_onsend_callbacks2(TMCB_REQUEST_SENT, t,
 													&onsend_params);
 					}
 #endif