[asterisk-commits] mmichelson: branch mmichelson/timeout_fixes r373846 - /team/mmichelson/timeou...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Sep 26 14:57:14 CDT 2012
Author: mmichelson
Date: Wed Sep 26 14:57:08 2012
New Revision: 373846
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=373846
Log:
Fix bad timeout logic in channels directory.
Modified:
team/mmichelson/timeout_fixes/channels/chan_agent.c
team/mmichelson/timeout_fixes/channels/chan_dahdi.c
team/mmichelson/timeout_fixes/channels/chan_iax2.c
team/mmichelson/timeout_fixes/channels/sig_analog.c
team/mmichelson/timeout_fixes/channels/sig_pri.c
Modified: team/mmichelson/timeout_fixes/channels/chan_agent.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/channels/chan_agent.c?view=diff&rev=373846&r1=373845&r2=373846
==============================================================================
--- team/mmichelson/timeout_fixes/channels/chan_agent.c (original)
+++ team/mmichelson/timeout_fixes/channels/chan_agent.c Wed Sep 26 14:57:08 2012
@@ -1045,6 +1045,7 @@
int res=0;
int to = 1000;
struct ast_frame *f;
+ struct timeval start = ast_tvnow();
/* Wait a second and look for something */
@@ -1052,12 +1053,13 @@
if (!p->chan)
return -1;
- for(;;) {
- to = ast_waitfor(p->chan, to);
- if (to < 0)
- return -1;
- if (!to)
- return 0;
+ while (ast_tvdiff_ms(ast_tvnow(), start) < to) {
+ int ms = ast_remaining_ms(start, to);
+
+ res = ast_waitfor(p->chan, ms);
+ if (res <= 0) {
+ return res;
+ }
f = ast_read(p->chan);
if (!f)
return -1;
Modified: team/mmichelson/timeout_fixes/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/channels/chan_dahdi.c?view=diff&rev=373846&r1=373845&r2=373846
==============================================================================
--- team/mmichelson/timeout_fixes/channels/chan_dahdi.c (original)
+++ team/mmichelson/timeout_fixes/channels/chan_dahdi.c Wed Sep 26 14:57:08 2012
@@ -7233,6 +7233,7 @@
int priority = 0;
struct ast_channel *oc0, *oc1;
enum ast_bridge_result res;
+ struct timeval start = ast_tvnow();
#ifdef PRI_2BCT
int triedtopribridge = 0;
q931_call *q931c0;
@@ -7454,6 +7455,7 @@
for (;;) {
struct ast_channel *c0_priority[2] = {c0, c1};
struct ast_channel *c1_priority[2] = {c1, c0};
+ int ms = ast_remaining_ms(start, timeoutms);
/* Here's our main loop... Start by locking things, looking for private parts,
and then balking if anything is wrong */
@@ -7474,7 +7476,7 @@
ast_channel_unlock(c0);
ast_channel_unlock(c1);
- if (!timeoutms ||
+ if (!ms ||
(op0 != p0) ||
(op1 != p1) ||
(ofd0 != c0->fds[0]) ||
@@ -7522,7 +7524,7 @@
}
#endif
- who = ast_waitfor_n(priority ? c0_priority : c1_priority, 2, &timeoutms);
+ who = ast_waitfor_n(priority ? c0_priority : c1_priority, 2, &ms);
if (!who) {
ast_debug(1, "Ooh, empty read...\n");
continue;
@@ -10500,6 +10502,8 @@
/* If set to use DTMF CID signalling, listen for DTMF */
if (p->cid_signalling == CID_SIG_DTMF) {
int k = 0;
+ int off_ms;
+ struct timeval start = ast_tvnow();
cs = NULL;
ast_debug(1, "Receiving DTMF cid on channel %s\n", chan->name);
dahdi_setlinear(p->subs[idx].dfd, 0);
@@ -10510,10 +10514,12 @@
* can drop some of them.
*/
ast_set_flag(chan, AST_FLAG_END_DTMF_ONLY);
- res = 4000;/* This is a typical OFF time between rings. */
- for (;;) {
+ off_ms = 4000;/* This is a typical OFF time between rings. */
+ while (ast_tvdiff_ms(ast_tvnow(), start) < off_ms) {
struct ast_frame *f;
- res = ast_waitfor(chan, res);
+ int ms = ast_remaining_ms(start, off_ms);
+
+ res = ast_waitfor(chan, ms);
if (res <= 0) {
/*
* We do not need to restore the dahdi_setlinear()
@@ -10556,6 +10562,8 @@
} else if ((p->cid_signalling == CID_SIG_V23) || (p->cid_signalling == CID_SIG_V23_JP)) {
cs = callerid_new(p->cid_signalling);
if (cs) {
+ int off_ms;
+ struct timeval start;
samples = 0;
#if 1
bump_gains(p);
@@ -10632,10 +10640,13 @@
}
/* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
- res = 4000;/* This is a typical OFF time between rings. */
- for (;;) {
+ start = ast_tvnow();
+ off_ms = 4000;/* This is a typical OFF time between rings. */
+ while (ast_tvdiff_ms(ast_tvnow(), start) < off_ms) {
struct ast_frame *f;
- res = ast_waitfor(chan, res);
+ int ms = ast_remaining_ms(start, off_ms);
+
+ res = ast_waitfor(chan, ms);
if (res <= 0) {
ast_log(LOG_WARNING, "CID timed out waiting for ring. "
"Exiting simple switch\n");
@@ -10763,12 +10774,17 @@
} else if (p->use_callerid && p->cid_start == CID_START_RING) {
if (p->cid_signalling == CID_SIG_DTMF) {
int k = 0;
+ int off_ms;
+ struct timeval start;
cs = NULL;
dahdi_setlinear(p->subs[idx].dfd, 0);
- res = 2000;
- for (;;) {
+ off_ms = 2000;
+ start = ast_tv_now();
+ while (ast_tvdiff_ms(ast_tvnow(), start) < off_ms) {
struct ast_frame *f;
- res = ast_waitfor(chan, res);
+ int ms = ast_remaining_ms(start, off_ms);
+
+ res = ast_waitfor(chan, ms);
if (res <= 0) {
ast_log(LOG_WARNING, "DTMFCID timed out waiting for ring. "
"Exiting simple switch\n");
Modified: team/mmichelson/timeout_fixes/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/channels/chan_iax2.c?view=diff&rev=373846&r1=373845&r2=373846
==============================================================================
--- team/mmichelson/timeout_fixes/channels/chan_iax2.c (original)
+++ team/mmichelson/timeout_fixes/channels/chan_iax2.c Wed Sep 26 14:57:08 2012
@@ -5558,6 +5558,11 @@
}
to = 1000;
who = ast_waitfor_n(cs, 2, &to);
+ /* XXX This will need to be updated to calculate
+ * timeout correctly once timeoutms is allowed to be
+ * > 0. Right now, this can go badly if the waitfor
+ * times out in less than a millisecond
+ */
if (timeoutms > -1) {
timeoutms -= (1000 - to);
if (timeoutms < 0)
@@ -13703,6 +13708,7 @@
/* By here we must have a dp */
if (dp->flags & CACHE_FLAG_PENDING) {
+ struct timeval start;
/* Okay, here it starts to get nasty. We need a pipe now to wait
for a reply to come back so long as it's pending */
for (x = 0; x < ARRAY_LEN(dp->waiters); x++) {
@@ -13727,8 +13733,10 @@
if (chan)
old = ast_channel_defer_dtmf(chan);
doabort = 0;
- while(timeout) {
- c = ast_waitfor_nandfds(&chan, chan ? 1 : 0, &com[0], 1, NULL, &outfd, &timeout);
+ start = ast_tvnow();
+ while (ast_tvdiff_ms(ast_tvnow(), start) < timeout) {
+ int ms = ast_remaining_ms(start, timeout);
+ c = ast_waitfor_nandfds(&chan, chan ? 1 : 0, &com[0], 1, NULL, &outfd, &ms);
if (outfd > -1)
break;
if (!c)
Modified: team/mmichelson/timeout_fixes/channels/sig_analog.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/channels/sig_analog.c?view=diff&rev=373846&r1=373845&r2=373846
==============================================================================
--- team/mmichelson/timeout_fixes/channels/sig_analog.c (original)
+++ team/mmichelson/timeout_fixes/channels/sig_analog.c Wed Sep 26 14:57:08 2012
@@ -2386,6 +2386,8 @@
if (p->cid_signalling == CID_SIG_DTMF) {
int k = 0;
int oldlinearity;
+ int timeout_ms;
+ struct timeval start = ast_tvnow();
cs = NULL;
ast_debug(1, "Receiving DTMF cid on channel %s\n", chan->name);
@@ -2398,10 +2400,12 @@
* can drop some of them.
*/
ast_set_flag(chan, AST_FLAG_END_DTMF_ONLY);
- res = 4000;/* This is a typical OFF time between rings. */
- for (;;) {
+ timeout_ms = 4000;/* This is a typical OFF time between rings. */
+ while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
struct ast_frame *f;
- res = ast_waitfor(chan, res);
+ int ms = ast_remaining_ms(start, timeout_ms);
+
+ res = ast_waitfor(chan, ms);
if (res <= 0) {
/*
* We do not need to restore the analog_set_linear_mode()
@@ -2456,6 +2460,8 @@
numbuf[0] = 0;
if (!analog_start_cid_detect(p, p->cid_signalling)) {
+ int off_ms;
+ struct timeval off_start;
while (1) {
res = analog_get_callerid(p, namebuf, numbuf, &ev, timeout - ast_tvdiff_ms(ast_tvnow(), start));
@@ -2493,9 +2499,12 @@
}
/* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
- res = 4000;/* This is a typical OFF time between rings. */
- for (;;) {
+ off_start = ast_tvnow();
+ off_ms = 4000;/* This is a typical OFF time between rings. */
+ while (ast_tvdiff_ms(ast_tvnow(), off_start) < off_ms) {
struct ast_frame *f;
+ int ms = ast_remaining_ms(off_start, off_ms);
+
res = ast_waitfor(chan, res);
if (res <= 0) {
ast_log(LOG_WARNING, "CID timed out waiting for ring. "
Modified: team/mmichelson/timeout_fixes/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/timeout_fixes/channels/sig_pri.c?view=diff&rev=373846&r1=373845&r2=373846
==============================================================================
--- team/mmichelson/timeout_fixes/channels/sig_pri.c (original)
+++ team/mmichelson/timeout_fixes/channels/sig_pri.c Wed Sep 26 14:57:08 2012
@@ -1831,7 +1831,7 @@
struct ast_frame *f;
char ex[80];
/* Wait up to 30 seconds for an answer */
- int newms, ms = 30000;
+ int timeout_ms = 30000;
ast_verb(3, "Initiating idle call on channel %s\n", chan->name);
snprintf(ex, sizeof(ex), "%d/%s", pvt->channel, pvt->pri->idledial);
@@ -1840,7 +1840,13 @@
ast_hangup(chan);
return NULL;
}
- while ((newms = ast_waitfor(chan, ms)) > 0) {
+ while (ast_tvdiff_ms(ast_tvnow(), start) < timeout_ms) {
+ int ms = ast_remaining_ms(start, timeout_ms);
+
+ if (ast_waitfor(chan, ms) <= 0) {
+ break;
+ }
+
f = ast_read(chan);
if (!f) {
/* Got hangup */
@@ -1866,7 +1872,6 @@
};
}
ast_frfree(f);
- ms = newms;
}
/* Hangup the channel since nothing happend */
ast_hangup(chan);
More information about the asterisk-commits
mailing list