summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuigi Rizzo <rizzo@icir.org>2006-10-19 10:05:02 +0000
committerLuigi Rizzo <rizzo@icir.org>2006-10-19 10:05:02 +0000
commit293330e7a906e70c332e78c5c47e60fb454ad554 (patch)
tree3120c2e74b52386c393ba40ebb1441fdd88a0fe7
parentd55365901783d94a38819946939da4c5f35fc2d4 (diff)
move a large block out of do_monitor() and into a function,
to improve readability. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@45668 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--channels/chan_sip.c102
1 files changed, 54 insertions, 48 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index cb1f81d16..f98bc35ac 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -14575,6 +14575,59 @@ static int does_peer_need_mwi(struct sip_peer *peer)
}
+/*! \brief helper function for the monitoring thread */
+static void check_rtp_timeout(struct sip_pvt *sip, time_t t)
+{
+ if (sip->rtp && sip->owner &&
+ (sip->owner->_state == AST_STATE_UP) &&
+ !sip->redirip.sin_addr.s_addr) {
+ if (sip->lastrtptx &&
+ sip->rtpkeepalive &&
+ (t > sip->lastrtptx + sip->rtpkeepalive)) {
+ /* Need to send an empty RTP packet */
+ sip->lastrtptx = time(NULL);
+ ast_rtp_sendcng(sip->rtp, 0);
+ }
+ if (sip->lastrtprx &&
+ (sip->rtptimeout || sip->rtpholdtimeout) &&
+ (t > sip->lastrtprx + sip->rtptimeout)) {
+ /* Might be a timeout now -- see if we're on hold */
+ struct sockaddr_in sin;
+ ast_rtp_get_peer(sip->rtp, &sin);
+ if (sin.sin_addr.s_addr ||
+ (sip->rtpholdtimeout &&
+ (t > sip->lastrtprx + sip->rtpholdtimeout))) {
+ /* Needs a hangup */
+ if (sip->rtptimeout) {
+ while (sip->owner && ast_channel_trylock(sip->owner)) {
+ ast_mutex_unlock(&sip->lock);
+ usleep(1);
+ ast_mutex_lock(&sip->lock);
+ }
+ if (sip->owner) {
+ if (!(ast_rtp_get_bridged(sip->rtp))) {
+ ast_log(LOG_NOTICE,
+ "Disconnecting call '%s' for lack of RTP activity in %ld seconds\n",
+ sip->owner->name,
+ (long) (t - sip->lastrtprx));
+ /* Issue a softhangup */
+ ast_softhangup_nolock(sip->owner, AST_SOFTHANGUP_DEV);
+ } else
+ ast_log(LOG_NOTICE, "'%s' will not be disconnected in %ld seconds because it is directly bridged to another RTP stream\n", sip->owner->name, (long) (t - sip->lastrtprx));
+ ast_channel_unlock(sip->owner);
+ /* forget the timeouts for this call, since a hangup
+ has already been requested and we don't want to
+ repeatedly request hangups
+ */
+ sip->rtptimeout = 0;
+ sip->rtpholdtimeout = 0;
+ }
+ }
+ }
+ }
+ }
+}
+
/*! \brief The SIP monitoring thread
\note This thread monitors all the SIP sessions and peers that needs notification of mwi
(and thus do not have a separate thread) indefinitely
@@ -14621,54 +14674,7 @@ restartsearch:
for (sip = iflist; !fastrestart && sip; sip = sip->next) {
ast_mutex_lock(&sip->lock);
/* Check RTP timeouts and kill calls if we have a timeout set and do not get RTP */
- if (sip->rtp && sip->owner &&
- (sip->owner->_state == AST_STATE_UP) &&
- !sip->redirip.sin_addr.s_addr) {
- if (sip->lastrtptx &&
- sip->rtpkeepalive &&
- (t > sip->lastrtptx + sip->rtpkeepalive)) {
- /* Need to send an empty RTP packet */
- sip->lastrtptx = time(NULL);
- ast_rtp_sendcng(sip->rtp, 0);
- }
- if (sip->lastrtprx &&
- (sip->rtptimeout || sip->rtpholdtimeout) &&
- (t > sip->lastrtprx + sip->rtptimeout)) {
- /* Might be a timeout now -- see if we're on hold */
- struct sockaddr_in sin;
- ast_rtp_get_peer(sip->rtp, &sin);
- if (sin.sin_addr.s_addr ||
- (sip->rtpholdtimeout &&
- (t > sip->lastrtprx + sip->rtpholdtimeout))) {
- /* Needs a hangup */
- if (sip->rtptimeout) {
- while (sip->owner && ast_channel_trylock(sip->owner)) {
- ast_mutex_unlock(&sip->lock);
- usleep(1);
- ast_mutex_lock(&sip->lock);
- }
- if (sip->owner) {
- if (!(ast_rtp_get_bridged(sip->rtp))) {
- ast_log(LOG_NOTICE,
- "Disconnecting call '%s' for lack of RTP activity in %ld seconds\n",
- sip->owner->name,
- (long) (t - sip->lastrtprx));
- /* Issue a softhangup */
- ast_softhangup_nolock(sip->owner, AST_SOFTHANGUP_DEV);
- } else
- ast_log(LOG_NOTICE, "'%s' will not be disconnected in %ld seconds because it is directly bridged to another RTP stream\n", sip->owner->name, (long) (t - sip->lastrtprx));
- ast_channel_unlock(sip->owner);
- /* forget the timeouts for this call, since a hangup
- has already been requested and we don't want to
- repeatedly request hangups
- */
- sip->rtptimeout = 0;
- sip->rtpholdtimeout = 0;
- }
- }
- }
- }
- }
+ check_rtp_timeout(sip, t);
/* If we have sessions that needs to be destroyed, do it now */
if (ast_test_flag(&sip->flags[0], SIP_NEEDDESTROY) && !sip->packets &&
!sip->owner) {