[Asterisk-Dev] Patch to allow for timeouts while calls in queue are waiting
Ted Cabeen
ted at impulse.net
Thu Jan 15 14:17:23 MST 2004
Here is a patch that I wrote that allows callers who are waiting in a
queue to timeout and move on if they spend more than a specified
amount of time waiting. Note that this is separate from the normal
timeout variable, which only applies when a call is being sent to a
member of the queue. This timeout applies while a caller is waiting
in the queue and there are other callers ahead of them. The code
defaults to an infinite timeout, so it will not cause any change in
behavior for asterisk. Can this get looked over and committed if
possible? Thanks.
--
Ted Cabeen
Sr. Systems/Network Administrator
Impulse Internet Services
--------------------------------------------------------------------------
Index: apps/app_queue.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_queue.c,v
retrieving revision 1.40
diff -u -r1.40 app_queue.c
--- apps/app_queue.c 19 Nov 2003 21:56:45 -0000 1.40
+++ apps/app_queue.c 15 Jan 2004 21:12:36 -0000
@@ -56,6 +56,7 @@
#define DEFAULT_RETRY 5
#define DEFAULT_TIMEOUT 15
+#define DEFAULT_WAITING_TIMEOUT 0
#define RECHECK 1 /* Recheck every second to see we we're at the top yet */
static char *tdesc = "True Call Queueing";
@@ -161,6 +162,7 @@
int dead; /* Whether this queue is dead or not */
int retry; /* Retry calling everyone after this amount of time */
int timeout; /* How long to wait for an answer */
+ int waitingtimeout; /* How long to wait for an agent */
/* Queue strategy things */
@@ -610,6 +612,8 @@
{
struct queue_ent *ch;
int res = 0;
+ int waitingtimeout = qe->parent->waitingtimeout;
+ int timeelapsed = 0;
for (;;) {
/* Atomically read the parent head -- does not need a lock */
ch = qe->parent->head;
@@ -620,6 +624,11 @@
res = ast_waitfordigit(qe->chan, RECHECK * 1000);
if (res)
break;
+ timeelapsed += RECHECK;
+ if (waitingtimeout > 0 && timeelapsed >= waitingtimeout) {
+ res = -1;
+ break;
+ }
}
return res;
}
@@ -1145,7 +1154,7 @@
/* If they hungup, return immediately */
if (res < 0) {
if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "User disconnected while waiting their turn\n");
+ ast_verbose(VERBOSE_PREFIX_3 "User disconnected or timed out while waiting their turn\n");
res = -1;
}
break;
@@ -1241,6 +1250,7 @@
q->dead = 0;
q->retry = 0;
q->timeout = -1;
+ q->waitingtimeout = -1;
q->maxlen = 0;
free_members(q, 0);
strcpy(q->moh, "");
@@ -1290,6 +1300,8 @@
strncpy(q->context, var->value, sizeof(q->context) - 1);
} else if (!strcasecmp(var->name, "timeout")) {
q->timeout = atoi(var->value);
+ } else if (!strcasecmp(var->name, "waitingtimeout")) {
+ q->waitingtimeout = atoi(var->value);
} else if (!strcasecmp(var->name, "retry")) {
q->retry = atoi(var->value);
} else if (!strcasecmp(var->name, "maxlen")) {
@@ -1309,6 +1321,8 @@
q->retry = DEFAULT_RETRY;
if (q->timeout < 0)
q->timeout = DEFAULT_TIMEOUT;
+ if (q->waitingtimeout < 0)
+ q->timeout = DEFAULT_WAITING_TIMEOUT;
if (q->maxlen < 0)
q->maxlen = 0;
if (!new)
Index: configs/queues.conf.sample
===================================================================
RCS file: /usr/cvsroot/asterisk/configs/queues.conf.sample,v
retrieving revision 1.5
diff -u -r1.5 queues.conf.sample
--- configs/queues.conf.sample 2 Aug 2003 21:10:06 -0000 1.5
+++ configs/queues.conf.sample 15 Jan 2004 21:12:36 -0000
@@ -45,6 +45,10 @@
;
;timeout = 15
;
+; How long do we let the call wait in the queue before a timeout (0 = forever)
+;
+;waitingtimeout = 0
+;
; How long do we wait before trying all the members again?
;
;retry = 5
More information about the asterisk-dev
mailing list