[Pcsclite-cvs-commit] PCSC/src winscard_msg.c,1.12,1.13

rousseau@quantz.debian.org rousseau@quantz.debian.org
Wed, 15 Oct 2003 19:40:51 +0200


Update of /cvsroot/pcsclite/PCSC/src
In directory quantz:/tmp/cvs-serv23012

Modified Files:
	winscard_msg.c 
Log Message:
perform a round-robbin among clients to avoid starvation under heavy
load. Patch from Bettina Martelli.


Index: winscard_msg.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/winscard_msg.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- winscard_msg.c	24 Sep 2003 14:15:59 -0000	1.12
+++ winscard_msg.c	15 Oct 2003 17:40:49 -0000	1.13
@@ -196,9 +196,9 @@
 
 int SHMProcessEvents(psharedSegmentMsg msgStruct, int blocktime)
 {
-
+	static int last_client = 0;
 	static fd_set read_fd;
-	int i, selret, largeSock, rv;
+	int i, j, selret, largeSock, rv;
 	struct timeval tv;
 
 	largeSock = 0;
@@ -257,8 +257,11 @@
 		}
 	}
 
-	for (i = 0; i < PCSCLITE_MAX_APPLICATIONS; i++)
+	/* Start each time with the last client and go round, else
+	 * in case of much traffic only two clients will be serviced */
+	for (j = 0; j < PCSCLITE_MAX_APPLICATIONS; j++)
 	{
+		i = (j+last_client) % PCSCLITE_MAX_APPLICATIONS;
 		if (clientSockets[i].sd != -1)
 		{
 			if (FD_ISSET(clientSockets[i].sd, &read_fd))
@@ -282,6 +285,9 @@
 				/*
 				 * Set the identifier handle 
 				 */
+				last_client = i;
+				DebugLogB("SHMProcessEvents: correctly processed client: %d",
+					last_client);
 				msgStruct->request_id = clientSockets[i].sd;
 				return 1;
 			}