Index: apps/app_queue.c
===================================================================
--- apps/app_queue.c	(revision 41829)
+++ apps/app_queue.c	(working copy)
@@ -137,8 +137,9 @@
 "      'd' -- data-quality (modem) call (minimum delay).\n"
 "      'h' -- allow callee to hang up by hitting *.\n"
 "      'H' -- allow caller to hang up by hitting *.\n"
-"      'n' -- no retries on the timeout; will exit this application and \n"
-"             go to the next step.\n"
+"      'n' -- no retries on the timeout as defined in queues.conf\n"
+"             ;will exit this application and go to the next step.\n"
+"      'c' -- perform only one cycle of attempts to reach queue members\n"
 "      'r' -- ring instead of playing MOH\n"
 "      't' -- allow the called user transfer the calling user\n"
 "      'T' -- to allow the calling user to transfer the call.\n"
@@ -1826,7 +1827,7 @@
 
 #define AST_MAX_WATCHERS 256
 
-static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callattempt *outgoing, int *to, char *digit, int prebusies, int caller_disconnect)
+static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callattempt *outgoing, int *to, char *digit, int prebusies, int caller_disconnect, int norepeat)
 {
 	char *queue = qe->parent->name;
 	struct callattempt *o;
@@ -2012,7 +2013,8 @@
 					if (qe->parent->strategy != QUEUE_STRATEGY_RINGALL) {
 						if (qe->parent->timeoutrestart)
 							*to = orig;
-						ring_one(qe, outgoing, &numbusies);
+						if (!norepeat)
+							ring_one(qe, outgoing, &numbusies);
 					}
 				}
 			}
@@ -2280,6 +2282,7 @@
 	struct ast_app *mixmonapp = NULL;
 	char *p;
 	char vars[2048];
+	int norepeat = 0;
 
 	memset(&bridge_config, 0, sizeof(bridge_config));
 	time(&now);
@@ -2308,8 +2311,11 @@
 			ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT);
 			break;
 		case 'n':
-			if ((now - qe->start >= qe->parent->timeout))
+			if ((now - qe->start >= qe->parent->timeout)) {
 				*go_on = 1;
+				norepeat = 1;
+				return 0;
+			}	
 			break;
 		}
 
@@ -2364,7 +2370,7 @@
 	ast_mutex_unlock(&qe->parent->lock);
 	if (use_weight)
 		AST_LIST_UNLOCK(&queues);
-	lpeer = wait_for_answer(qe, outgoing, &to, &digit, numbusies, ast_test_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT));
+	lpeer = wait_for_answer(qe, outgoing, &to, &digit, numbusies, ast_test_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT), norepeat);
 	ast_mutex_lock(&qe->parent->lock);
 	if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY) {
 		store_next(qe, outgoing);
@@ -3222,6 +3228,7 @@
 	enum queue_result reason = QUEUE_UNKNOWN;
 	/* whether to exit Queue application after the timeout hits */
 	int go_on = 0;
+	int onecycle = 0;
 	char *parse;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(queuename);
@@ -3289,6 +3296,8 @@
 
 	if (args.options && (strchr(args.options, 'r')))
 		ringing = 1;
+	if (args.options && (strchr(args.options, 'c')))
+		onecycle = 1;
 
 	if (option_debug)
 		ast_log(LOG_DEBUG, "queue: %s, options: %s, url: %s, announce: %s, expires: %ld, priority: %d\n",
@@ -3373,6 +3382,25 @@
 
 				/* Try calling all queue members for 'timeout' seconds */
 				res = try_calling(&qe, args.options, args.announceoverride, args.url, &go_on, args.agi);
+				/* exit after 'timeout' cycle if 'n' option enabled */
+				if (go_on) {
+					if (option_verbose > 2)
+						ast_verbose(VERBOSE_PREFIX_3 "Exiting on time-out cycle\n");
+					ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
+					record_abandoned(&qe);
+					reason = QUEUE_TIMEOUT;
+					res = 0;
+					break;
+				}
+				/* exit after one cycle */
+				if (onecycle && !res) {
+					if (option_verbose > 2)
+						ast_verbose(VERBOSE_PREFIX_3 "Done with one cycle, time to exit.\n");
+					ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITAFTERCYCLE", "%d", qe.pos);	
+					reason = QUEUE_TIMEOUT;
+					res = 0;
+					break;
+				}
 				if (res) {
 					if (res < 0) {
 						if (!qe.handled) {
@@ -3430,16 +3458,6 @@
 					ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
 					break;
 				}
-				/* exit after 'timeout' cycle if 'n' option enabled */
-				if (go_on) {
-					if (option_verbose > 2)
-						ast_verbose(VERBOSE_PREFIX_3 "Exiting on time-out cycle\n");
-					ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
-					record_abandoned(&qe);
-					reason = QUEUE_TIMEOUT;
-					res = 0;
-					break;
-				}
 				/* Since this is a priority queue and
 				 * it is not sure that we are still at the head
 				 * of the queue, go and check for our turn again.
