[Asterisk-cvs] asterisk channel.c,1.81,1.82

markster at lists.digium.com markster at lists.digium.com
Fri Mar 5 13:31:08 CST 2004


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv9514

Modified Files:
	channel.c 
Log Message:
Consider whentohangup in timeout (bug #1107)


Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- channel.c	4 Mar 2004 01:11:25 -0000	1.81
+++ channel.c	5 Mar 2004 18:22:31 -0000	1.82
@@ -809,15 +809,25 @@
 	fd_set rfds, efds;
 	int res;
 	int x, y, max=-1;
+	time_t now;
+	long whentohangup = 0, havewhen = 0, diff;
 	struct ast_channel *winner = NULL;
 	if (outfd)
-		*outfd = -1;
+		*outfd = -99999;
 	if (exception)
 		*exception = 0;
 	
+	time(&now);
 	/* Perform any pending masquerades */
 	for (x=0;x<n;x++) {
 		ast_mutex_lock(&c[x]->lock);
+		if (c[x]->whentohangup) {
+			diff = c[x]->whentohangup - now;
+			if (!havewhen || (diff < whentohangup)) {
+				havewhen++;
+				whentohangup = diff;
+			}
+		}
 		if (c[x]->masq) {
 			if (ast_do_masquerade(c[x], 1)) {
 				ast_log(LOG_WARNING, "Masquerade failed\n");
@@ -831,6 +841,13 @@
 	
 	tv.tv_sec = *ms / 1000;
 	tv.tv_usec = (*ms % 1000) * 1000;
+	
+	if (havewhen) {
+		if ((*ms < 0) || (whentohangup * 1000 < *ms)) {
+			tv.tv_sec = whentohangup / 1000;
+			tv.tv_usec = (whentohangup % 1000) * 1000;
+		}
+	}
 	FD_ZERO(&rfds);
 	FD_ZERO(&efds);
 
@@ -851,7 +868,7 @@
 		if (fds[x] > max)
 			max = fds[x];
 	}
-	if (*ms >= 0)
+	if ((*ms >= 0) || (havewhen))
 		res = ast_select(max + 1, &rfds, NULL, &efds, &tv);
 	else
 		res = ast_select(max + 1, &rfds, NULL, &efds, NULL);




More information about the svn-commits mailing list