[Freeswitch-dev] patch for switch_ivr_sleep break behavior
Steve Richardson
steve at comrex.com
Thu Jun 23 22:43:52 MSD 2011
I noticed that the dialplan tools "sleep" function would not respond to
"break" if the call did not have ready media (e.g., if it was still
ringing and not bridged anywhere).
The dptools sleep is just a wrapper call for switch_ivr_sleep(), and I
made a small patch for it to look for a break in the case where the
media was not ready.
I don't know if this has a negative effect on other uses of
switch_ivr_sleep() in freeswitch, but for my application this allows me
to break a sleeping channel when the media is not ready, allowing it to
proceed. Instead of yielding for the full sleep time, it yields in
small increments and checks for break after each yield. I chose 20ms,
but my application would probably tolerate 100ms without much impact. I
don't know if there's a more elegant way to do this, but I'm certainly
open to suggestion.
Patch follows for your consideration:
diff --git a/src/switch_ivr.c b/src/switch_ivr.c
index 92eb97e..6c1202a 100644
--- a/src/switch_ivr.c
+++ b/src/switch_ivr.c
@@ -151,7 +151,15 @@ SWITCH_DECLARE(switch_status_t)
switch_ivr_sleep(switch_core_session_t *session,
*/
if (!switch_channel_media_ready(channel)) {
- switch_yield(ms * 1000);
+
+ for (elapsed=0; elapsed<(ms/20); elapsed++) {
+ if (switch_channel_test_flag(channel, CF_BREAK)) {
+ switch_channel_clear_flag(channel,
CF_BREAK);
+ return SWITCH_STATUS_BREAK;
+ }
+
+ switch_yield(20 * 1000);
+ }
return SWITCH_STATUS_SUCCESS;
}
regards,
Steve
--
*Stephen Richardson
Senior Software Engineer*
Comrex Corporation
19 Pine Rd
Devens MA 01434 USA
v 978.784.1764
f 978.784.1717
steve at comrex.com <mailto:steve at comrex.com>
http://www.comrex.com/
More information about the FreeSWITCH-dev
mailing list