[svn-commits] rizzo: branch rizzo/astobj2 r47449 - /team/rizzo/astobj2/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Fri Nov 10 11:19:26 MST 2006


Author: rizzo
Date: Fri Nov 10 12:19:26 2006
New Revision: 47449

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47449
Log:
simplify retrans_pkt()


Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=47449&r1=47448&r2=47449
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Fri Nov 10 12:19:26 2006
@@ -1945,39 +1945,30 @@
 static int retrans_pkt(void *data)
 {
 	struct sip_pkt *pkt = data, *prev, *cur = NULL;
-	int reschedule = DEFAULT_RETRANS;
 	struct sip_pvt *pvt = pkt->pvt;	/* XXX we assume it is not null. maybe should check ? */
 
 	/* Lock channel PVT */
 	sip_pvt_lock(pvt);
 
 	if (pkt->retrans < MAX_RETRANS) {
+		int reschedule;
+
 		pkt->retrans++;
+		/* compute the next retransmission timeout */
  		if (!pkt->timer_t1) {	/* Re-schedule using timer_a and timer_t1 */
-			if (sipdebug && option_debug > 3)
- 				ast_log(LOG_DEBUG, "SIP TIMER: Not rescheduling id #%d:%s (Method %d) (No timer T1)\n", pkt->retransid, sip_methods[pkt->method].text, pkt->method);
+			/* no rtt estimate, use default */
+			reschedule = DEFAULT_RETRANS;
 		} else {
- 			int siptimer_a;
-
- 			if (sipdebug && option_debug > 3)
- 				ast_log(LOG_DEBUG, "SIP TIMER: Rescheduling retransmission #%d (%d) %s - %d\n", pkt->retransid, pkt->retrans, sip_methods[pkt->method].text, pkt->method);
- 			if (!pkt->timer_a)
- 				pkt->timer_a = 2 ;
- 			else
- 				pkt->timer_a = 2 * pkt->timer_a;
+ 			if (pkt->timer_a == 0)	/* initialize */
+ 				pkt->timer_a = 1;
+			pkt->timer_a *= 2;
  
- 			/* For non-invites, a maximum of 4 secs */
- 			siptimer_a = pkt->timer_t1 * pkt->timer_a;	/* Double each time */
- 			if (pkt->method != SIP_INVITE && siptimer_a > 4000)
- 				siptimer_a = 4000;
- 		
- 			/* Reschedule re-transmit */
-			reschedule = siptimer_a;
- 			if (option_debug > 3)
- 				ast_log(LOG_DEBUG, "** SIP timers: Rescheduling retransmission %d to %d ms (t1 %d ms (Retrans id #%d)) \n", pkt->retrans +1, siptimer_a, pkt->timer_t1, pkt->retransid);
+ 			/* For non-invites, a maximum of 4 secs - otherwise unbounded ? */
+ 			reschedule = pkt->timer_t1 * pkt->timer_a;	/* Double each time */
+ 			if (pkt->method != SIP_INVITE && reschedule > 4000)
+ 				reschedule = 4000;
  		} 
-
-		if (sip_debug_test_pvt(pkt->pvt)) {
+		if (sip_debug_test_pvt(pvt)) {
 			const struct sockaddr_in *dst = sip_real_dst(pvt);
 			ast_verbose("Retransmitting #%d (%s) to %s:%d:\n%s\n---\n",
 				pkt->retrans, sip_nat_mode(pvt),
@@ -1987,13 +1978,22 @@
 
 		append_history(pvt, "ReTx", "%d %s", reschedule, pkt->data);
 		__sip_xmit(pvt, pkt->data, pkt->packetlen);
+		if (sipdebug && option_debug > 3)
+			ast_log(LOG_DEBUG, "** SIP timers: Rescheduling retransmission %d to %d ms (t1 %d ms t_a %d Retrans id #%d:%s)\n",
+				pkt->retrans+1, reschedule, pkt->timer_t1, pkt->timer_a,
+				pkt->retransid, sip_methods[pkt->method].text);
+
 		sip_pvt_unlock(pvt);
 		return  reschedule;
-	} 
+	}
+
 	/* Too many retries */
 	if (pkt->method != SIP_OPTIONS) {
 		if (ast_test_flag(pkt, FLAG_FATAL) || sipdebug)	/* Tell us if it's critical or if we're debugging */
-			ast_log(LOG_WARNING, "Maximum retries exceeded on transmission %s for seqno %d (%s %s)\n", pvt->callid, pkt->seqno, (ast_test_flag(pkt, FLAG_FATAL)) ? "Critical" : "Non-critical", (ast_test_flag(pkt, FLAG_RESPONSE)) ? "Response" : "Request");
+			ast_log(LOG_WARNING, "Maximum retries exceeded on transmission %s for seqno %d (%s %s)\n",
+				pvt->callid, pkt->seqno,
+				ast_test_flag(pkt, FLAG_FATAL) ? "Critical" : "Non-critical",
+				ast_test_flag(pkt, FLAG_RESPONSE) ? "Response" : "Request");
 	} else {
 		if ((pkt->method == SIP_OPTIONS) && sipdebug)
 			ast_log(LOG_WARNING, "Cancelling retransmit of OPTIONs (call id %s) \n", pvt->callid);
@@ -2017,22 +2017,21 @@
 			ast_set_flag(&pvt->flags[0], SIP_NEEDDESTROY);	
 		}
 	}
-	/* XXX this code needs to be fixed */
-	/* In any case, go ahead and remove the packet */
+
+	/* Remove the packet */
 	for (prev = NULL, cur = pvt->packets; cur; prev = cur, cur = cur->next) {
-		if (cur == pkt)
+		if (cur == pkt) {
+			if (prev)
+				prev->next = cur->next;
+			else
+				pvt->packets = cur->next;
+			pkt->pvt = pvt_unref(pvt);	/* release the reference pvt */
+			free(cur);
 			break;
+		}
 	}
 	if (!cur)
 		ast_log(LOG_WARNING, "Weird, couldn't find packet owner!\n");
-	else {
-		if (prev)
-			prev->next = cur->next;
-		else
-			pvt->packets = cur->next;
-		pkt->pvt = pvt_unref(pvt);	/* release the pvt */
-		free(cur);
-	}
 	sip_pvt_unlock(pvt);
 	return 0;
 }



More information about the svn-commits mailing list