esound r499 - trunk



Author: fejj
Date: Wed Jul 30 19:53:32 2008
New Revision: 499
URL: http://svn.gnome.org/viewvc/esound?rev=499&view=rev

Log:
	(write_timeout): Abort on all write() errors other than EINTR.


Modified:
   trunk/ChangeLog
   trunk/esdlib.c

Modified: trunk/esdlib.c
==============================================================================
--- trunk/esdlib.c	(original)
+++ trunk/esdlib.c	Wed Jul 30 19:53:32 2008
@@ -90,7 +90,7 @@
 	do {
 		pfd[0].revents = 0;
 		rv = poll (pfd, 1, 100);
-	} while (rv == -1 && errno == EINTR);
+	} while (rv == -1 && (errno == EINTR || errno == EAGAIN));
 	
 	if (rv < 1 || !(pfd[0].revents & POLLIN)) {
 		errno = ETIMEDOUT;
@@ -138,22 +138,29 @@
 		do {
 			pfd[0].revents = 0;
 			rv = poll (pfd, 1, 100);
-		} while (rv == -1 && errno == EINTR);
+		} while (rv == -1 && (errno == EINTR || errno == EAGAIN));
 		
-		if (rv < 1 || (pfd[0].revents & (POLLERR | POLLHUP))) {
+		/* Note: If the remote end of a socket is closed,
+		 * NetBSD will use POLLIN rather than POLLHUP if
+		 * POLLOUT was requested. */
+		if (rv < 1 || (pfd[0].revents & (POLLERR | POLLHUP | POLLIN | POLLOUT)) != POLLOUT) {
 			fcntl (fd, F_SETFL, flags);
 			errno = ETIMEDOUT;
 			return -1;
 		}
 		
-		if (pfd[0].revents & POLLOUT) {
-			do {
-				n = write (fd, buf + nwritten, buflen - nwritten);
-			} while (n == -1 && errno == EINTR);
-			
-			if (n > 0)
-				nwritten += n;
+		do {
+			n = write (fd, buf + nwritten, buflen - nwritten);
+		} while (n == -1 && errno == EINTR);
+		
+		if (n == -1) {
+			rv = errno;
+			fcntl (fd, F_SETFL, flags);
+			errno = rv;
+			return -1;
 		}
+		
+		nwritten += n;
 	} while (nwritten < buflen);
 	
 	fcntl (fd, F_SETFL, flags);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]