[svn-commits] russell: branch 1.4 r166297 - /branches/1.4/main/utils.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Dec 22 11:22:57 CST 2008


Author: russell
Date: Mon Dec 22 11:22:56 2008
New Revision: 166297

URL: http://svn.digium.com/view/asterisk?view=rev&rev=166297
Log:
Fix up timeout handling in ast_carefulwrite().

Modified:
    branches/1.4/main/utils.c

Modified: branches/1.4/main/utils.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/utils.c?view=diff&rev=166297&r1=166296&r2=166297
==============================================================================
--- branches/1.4/main/utils.c (original)
+++ branches/1.4/main/utils.c Mon Dec 22 11:22:56 2008
@@ -921,7 +921,9 @@
 
 int ast_carefulwrite(int fd, char *s, int len, int timeoutms) 
 {
+	struct timeval start = ast_tvnow();
 	int res = 0;
+	int elapsed = 0;
 
 	while (len) {
 		struct pollfd pfd = {
@@ -930,7 +932,7 @@
 		};
 
 		/* poll() until the fd is writable without blocking */
-		while ((res = poll(&pfd, 1, timeoutms)) <= 0) {
+		while ((res = poll(&pfd, 1, timeoutms - elapsed)) <= 0) {
 			if (res == 0) {
 				/* timed out. */
 				ast_log(LOG_NOTICE, "Timed out trying to write\n");
@@ -939,6 +941,13 @@
 				/* poll() returned an error, check to see if it was fatal */
 
 				if (errno == EINTR || errno == EAGAIN) {
+					elapsed = ast_tvdiff_ms(ast_tvnow(), start);
+					if (elapsed > timeoutms) {
+						/* We've taken too long to write 
+						 * This is only an error condition if we haven't finished writing. */
+						res = len ? -1 : 0;
+						break;
+					}
 					/* This was an acceptable error, go back into poll() */
 					continue;
 				}
@@ -967,6 +976,14 @@
 		len -= res;
 		s += res;
 		res = 0;
+
+		elapsed = ast_tvdiff_ms(ast_tvnow(), start);
+		if (elapsed > timeoutms) {
+			/* We've taken too long to write 
+			 * This is only an error condition if we haven't finished writing. */
+			res = len ? -1 : 0;
+			break;
+		}
 	}
 
 	return res;




More information about the svn-commits mailing list