Module: sip-router Branch: tmp/tm_async_reply_support Commit: 32a5c307937fe1c8d1a3f4f3adcfe9e790d16be7 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=32a5c307...
Author: Richard Good richard.good@smilecoms.com Committer: Richard Good richard.good@smilecoms.com Date: Mon Mar 18 11:50:51 2013 +0200
tm: First working version of suspend on reply
- First working version (though still needs to be 100% tested) for suspending and continuing on a SIP reply
---
modules/tm/t_suspend.c | 98 +++++++++++++++++++++++++++++------------------- receive.c | 12 +----- 2 files changed, 61 insertions(+), 49 deletions(-)
diff --git a/modules/tm/t_suspend.c b/modules/tm/t_suspend.c index 9aea87f..565f624 100644 --- a/modules/tm/t_suspend.c +++ b/modules/tm/t_suspend.c @@ -132,12 +132,12 @@ int t_suspend(struct sip_msg *msg, return -1; }
- //TODO do we need this? -// if (save_msg_lumps(t->uac[branch].reply, msg)) { -// LOG(L_ERR, "ERROR: t_suspend: " \ -// "failed to save the message lumps\n"); -// return -1; -// } +/* //TODO do we need this? + if (save_msg_lumps(t->uac[branch].reply, msg)) { + LOG(L_ERR, "ERROR: t_suspend: " \ + "failed to save the message lumps\n"); + return -1; + }*/
LOG(L_DBG,"DBG: Saving stuff to transaction"); /* set as suspend reply for when we continue */ @@ -273,6 +273,9 @@ int t_continue(unsigned int hash_index, unsigned int label,
LOG(L_DBG,"Unlocking transaction reply mutex"); UNLOCK_REPLIES(t); + LOG(L_DBG,"Unreffing the transaction"); + /* unref the transaction */ + t_unref(t->uas.request); }
}else{ @@ -380,11 +383,6 @@ int t_continue(unsigned int hash_index, unsigned int label, }
done: - - LOG(L_DBG,"Unreffing the transaction"); - /* unref the transaction */ - t_unref(t->uas.request); - return 0;
kill_trans: @@ -437,34 +435,56 @@ int t_cancel_suspend(unsigned int hash_index, unsigned int label) "transaction id mismatch\n"); return -1; } - /* The transaction does not need to be locked because this - * function is either executed from the original route block - * or from failure route which already locks */ - - reset_kr(); /* the blind UAC of t_suspend has set kr */ - - /* Try to find the blind UAC, and cancel its fr timer. - * We assume that the last blind uac called this function. */ - for ( branch = t->nr_of_outgoings-1; - branch >= 0 && t->uac[branch].request.buffer; - branch--); - - if (branch >= 0) { - stop_rb_timers(&t->uac[branch].request); - /* Set last_received to something >= 200, - * the actual value does not matter, the branch - * will never be picked up for response forwarding. - * If last_received is lower than 200, - * then the branch may tried to be cancelled later, - * for example when t_reply() is called from - * a failure rute => deadlock, because both - * of them need the reply lock to be held. */ - t->uac[branch].last_received=500; - } else { - /* Not a huge problem, fr timer will fire, but CANCEL - will not be sent. last_received will be set to 408. */ - return -1; - } + + + if (t->uas.suspended_request==1){ + t->uac[branch].suspended_reply = 0; + LOG(L_DBG,"This is a cancel suspend for a request"); + /* The transaction does not need to be locked because this + * function is either executed from the original route block + * or from failure route which already locks */ + + reset_kr(); /* the blind UAC of t_suspend has set kr */ + + /* Try to find the blind UAC, and cancel its fr timer. + * We assume that the last blind uac called this function. */ + for ( branch = t->nr_of_outgoings-1; + branch >= 0 && t->uac[branch].request.buffer; + branch--); + + if (branch >= 0) { + stop_rb_timers(&t->uac[branch].request); + /* Set last_received to something >= 200, + * the actual value does not matter, the branch + * will never be picked up for response forwarding. + * If last_received is lower than 200, + * then the branch may tried to be cancelled later, + * for example when t_reply() is called from + * a failure rute => deadlock, because both + * of them need the reply lock to be held. */ + t->uac[branch].last_received=500; + } else { + /* Not a huge problem, fr timer will fire, but CANCEL + will not be sent. last_received will be set to 408. */ + return -1; + } + }else{ + LOG(L_DBG,"This is a cancel suspend for a response"); + for ( branch = 0; + branch < t->nr_of_outgoings; + branch++ + ) { + //TODO not sure if this will work yet - think we need to pass which branch to continue when we call t_continue! + if (t->uac[branch].suspended_reply==1){ + LOG(L_DBG,"Found branch that has suspend reply set"); + LOG(L_DBG,"Disabling suspend branch"); + t->uac[branch].reply->flags &= ~FL_RPL_SUSPENDED; + if (t->uas.request) t->uas.request->flags&= ~FL_RPL_SUSPENDED; + t->uac[branch].suspended_reply = 0; + } + } + } +
return 0; } diff --git a/receive.c b/receive.c index e107cfa..a4018ff 100644 --- a/receive.c +++ b/receive.c @@ -265,12 +265,6 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info) STATS_RPL_FWD_DROP(); goto skip_send_reply; /* drop the message, no error */ } - - if (unlikely(ret==0 || msg->flags&FL_RPL_SUSPENDED)) { - goto skip_send_reply; - /* suspend the reply (async), no error */ - } - } /* send the msg */ forward_reply(msg); @@ -283,10 +277,8 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info) DBG("successfully ran reply processing...(%d usec)\n", diff); #endif
- if (likely(!(msg->flags&FL_RPL_SUSPENDED))) { - /* execute post reply-script callbacks */ - exec_post_script_cb(msg, ONREPLY_CB_TYPE); - } + /* execute post reply-script callbacks */ + exec_post_script_cb(msg, ONREPLY_CB_TYPE); }
end: