[Box Backup-commit] COMMIT r959 - box/chris/merge/lib/win32

subversion at fluffy.co.uk subversion at fluffy.co.uk
Mon Sep 4 00:58:43 BST 2006


Author: chris
Date: 2006-09-04 00:58:43 +0100 (Mon, 04 Sep 2006)
New Revision: 959

Modified:
   box/chris/merge/lib/win32/emu.cpp
Log:
(refs #3)

Improved poll() emulation to handle multiple fds


Modified: box/chris/merge/lib/win32/emu.cpp
===================================================================
--- box/chris/merge/lib/win32/emu.cpp	2006-09-03 23:57:08 UTC (rev 958)
+++ box/chris/merge/lib/win32/emu.cpp	2006-09-03 23:58:43 UTC (rev 959)
@@ -1079,10 +1079,10 @@
 		fd_set readfd;
 		fd_set writefd;
 
-		readfd.fd_count = 0;
-		writefd.fd_count = 0;
+		FD_ZERO(&readfd);
+		FD_ZERO(&writefd);
 
-		struct pollfd *ufdsTmp = ufds;
+		// struct pollfd *ufdsTmp = ufds;
 
 		timeval timOut;
 		timeval *tmpptr; 
@@ -1095,41 +1095,61 @@
 		timOut.tv_sec  = timeout / 1000;
 		timOut.tv_usec = timeout * 1000;
 
-		if (ufds->events & POLLIN)
+		for (unsigned long i = 0; i < nfds; i++)
 		{
-			for (unsigned long i = 0; i < nfds; i++)
+			struct pollfd* ufd = &(ufds[i]);
+
+			if (ufd->events & POLLIN)
 			{
-				readfd.fd_array[i] = ufdsTmp->fd;
-				readfd.fd_count++;
+				FD_SET(ufd->fd, &readfd);
 			}
-		}
 
-		if (ufds->events & POLLOUT)
-		{
-			for (unsigned long i = 0; i < nfds; i++)
+			if (ufd->events & POLLOUT)
 			{
+				FD_SET(ufd->fd, &writefd);
+			}
 
-				writefd.fd_array[i]=ufdsTmp->fd;
-				writefd.fd_count++;
+			if (ufd->events & ~(POLLIN | POLLOUT))
+			{
+				printf("Unsupported poll bits %d",
+					ufd->events);
+				return -1;
 			}
 		}	
 
-		int noffds = select(0, &readfd, &writefd, 0, tmpptr);
+		int nready = select(0, &readfd, &writefd, 0, tmpptr);
 
-		if (noffds == SOCKET_ERROR)
+		if (nready == SOCKET_ERROR)
 		{
 			// int errval = WSAGetLastError();
 
-			ufdsTmp = ufds;
+			struct pollfd* pufd = ufds;
 			for (unsigned long i = 0; i < nfds; i++)
 			{
-				ufdsTmp->revents = POLLERR;
-				ufdsTmp++;
+				pufd->revents = POLLERR;
+				pufd++;
 			}
 			return (-1);
 		}
+		else if (nready > 0)
+		{
+			for (unsigned long i = 0; i < nfds; i++)
+			{
+				struct pollfd *ufd = &(ufds[i]);
 
-		return noffds;
+				if (FD_ISSET(ufd->fd, &readfd))
+				{
+					ufd->revents |= POLLIN;
+				}
+
+				if (FD_ISSET(ufd->fd, &writefd))
+				{
+					ufd->revents |= POLLOUT;
+				}
+			}
+		}
+
+		return nready;
 	}
 	catch (...)
 	{




More information about the Boxbackup-commit mailing list