From 3845299e46ce0c122ef479a9207a9a7ce21d42ca Mon Sep 17 00:00:00 2001 From: Gregory Nietsky Date: Sat, 12 Nov 2011 16:32:45 +0000 Subject: mISDN Round Robin break when no channel is available Prevent channels been parsed repetitively. ........ Merged revisions 344965 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 344966 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@344979 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_misdn.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'channels/chan_misdn.c') diff --git a/channels/chan_misdn.c b/channels/chan_misdn.c index 9945b2c8f..30b104452 100644 --- a/channels/chan_misdn.c +++ b/channels/chan_misdn.c @@ -7891,6 +7891,7 @@ static struct ast_channel *misdn_request(const char *type, struct ast_format_cap int port_up; int check; int maxbchans; + int wraped = 0; if (!rr->port) { rr->port = misdn_cfg_get_next_port_spin(0); @@ -7905,6 +7906,7 @@ static struct ast_channel *misdn_request(const char *type, struct ast_format_cap do { misdn_cfg_get(rr->port, MISDN_CFG_GROUPNAME, cfg_group, sizeof(cfg_group)); if (strcasecmp(cfg_group, group)) { + wraped = 1; rr->port = misdn_cfg_get_next_port_spin(rr->port); rr->channel = 1; continue; @@ -7926,6 +7928,11 @@ static struct ast_channel *misdn_request(const char *type, struct ast_format_cap maxbchans = misdn_lib_get_maxchans(rr->port); for (;rr->channel <= maxbchans;rr->channel++) { + /* ive come full circle and can stop now */ + if (wraped && (rr->port == port_start) && (rr->channel == bchan_start)) { + break; + } + chan_misdn_log(4, rr->port, "Checking channel %d\n", rr->channel); if ((newbc = misdn_lib_get_free_bc(rr->port, rr->channel, 0, 0))) { @@ -7934,15 +7941,16 @@ static struct ast_channel *misdn_request(const char *type, struct ast_format_cap break; } } - if (!newbc || (rr->channel > maxbchans)) { + if (wraped && (rr->port == port_start) && (rr->channel <= bchan_start)) { + break; + } else if (!newbc || (rr->channel == maxbchans)) { rr->port = misdn_cfg_get_next_port_spin(rr->port); rr->channel = 1; } } - } while (!newbc && (rr->port > 0) && - ((rr->port != port_start) || ((rr->port == port_start) && (rr->channel < bchan_start)))); - + wraped = 1; + } while (!newbc && (rr->port > 0)); } else { for (port = misdn_cfg_get_next_port(0); port > 0; port = misdn_cfg_get_next_port(port)) { -- cgit v1.2.3