[Pcsclite-cvs-commit] r4719 - /trunk/PCSC/src/winscard_clnt.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Mon Feb 8 16:10:29 UTC 2010


Author: rousseau
Date: Mon Feb  8 16:10:23 2010
New Revision: 4719

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=4719
Log:
Make SCardReconnect(), SCardStatus() and SCardTransmit() block instead
of returning SCARD_E_SHARING_VIOLATION immediately. These functions will
then behave like on Windows.

This can happen if these functions are called when the reader is locked
by a PCSC transaction (SCardBeginTransaction/SCardEndTransaction).

You can define the environment variable PCSCLITE_NO_BLOCKING to use the
old behavior.

Thanks to Jean-Luc Giraud for the patch.
http://archives.neohapsis.com/archives/dev/muscle/2010-q1/0041.html

Modified:
    trunk/PCSC/src/winscard_clnt.c

Modified: trunk/PCSC/src/winscard_clnt.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_clnt.c?rev=4719&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_clnt.c (original)
+++ trunk/PCSC/src/winscard_clnt.c Mon Feb  8 16:10:23 2010
@@ -107,6 +107,7 @@
 #define FALSE 0
 #endif
 
+static char sharing_shall_block = TRUE;
 
 #undef DO_PROFILE
 #ifdef DO_PROFILE
@@ -527,6 +528,12 @@
 			return SCARD_E_NO_MEMORY;
 		}
 
+		if (getenv("PCSCLITE_NO_BLOCKING"))
+		{
+			Log1(PCSC_LOG_INFO, "Disable shared blocking");
+			sharing_shall_block = FALSE;
+		}
+		
 		isExecuted = 1;
 	}
 
@@ -989,6 +996,9 @@
 		 * -> so the mMutex has been unlocked */
 		return SCARD_E_INVALID_HANDLE;
 
+	/* Retry loop for blocking behaviour */
+retry:
+	
 	scReconnectStruct.hCard = hCard;
 	scReconnectStruct.dwShareMode = dwShareMode;
 	scReconnectStruct.dwPreferredProtocols = dwPreferredProtocols;
@@ -1021,6 +1031,13 @@
 		goto end;
 	}
 
+	if (sharing_shall_block
+		&& (SCARD_E_SHARING_VIOLATION == scReconnectStruct.rv))
+	{
+		(void)SYS_USleep(PCSCLITE_LOCK_POLL_RATE);
+		goto retry;
+	}
+	
 	*pdwActiveProtocol = scReconnectStruct.dwActiveProtocol;
 	rv = scReconnectStruct.rv;
 
@@ -1602,6 +1619,9 @@
 		goto end;
 	}
 
+	/* Retry loop for blocking behaviour */
+retry:
+
 	/* initialise the structure */
 	memset(&scStatusStruct, 0, sizeof(scStatusStruct));
 	scStatusStruct.hCard = hCard;
@@ -1633,6 +1653,13 @@
 		goto end;
 	}
 
+	if (sharing_shall_block
+		&& (SCARD_E_SHARING_VIOLATION == scStatusStruct.rv))
+	{
+		(void)SYS_USleep(PCSCLITE_LOCK_POLL_RATE);
+		goto retry;
+	}
+	
 	rv = scStatusStruct.rv;
 	if (rv != SCARD_S_SUCCESS && rv != SCARD_E_INSUFFICIENT_BUFFER)
 	{
@@ -2835,6 +2862,9 @@
 		goto end;
 	}
 
+	/* Retry loop for blocking behaviour */
+retry:
+	
 	scTransmitStruct.hCard = hCard;
 	scTransmitStruct.cbSendLength = cbSendLength;
 	scTransmitStruct.pcbRecvLength = *pcbRecvLength;
@@ -2905,6 +2935,13 @@
 			pioRecvPci->cbPciLength = scTransmitStruct.ioRecvPciLength;
 		}
 	}
+	if (sharing_shall_block
+		&& (SCARD_E_SHARING_VIOLATION == scTransmitStruct.rv))
+	{
+		(void)SYS_USleep(PCSCLITE_LOCK_POLL_RATE);
+		goto retry;
+	}
+	
 
 	*pcbRecvLength = scTransmitStruct.pcbRecvLength;
 	rv = scTransmitStruct.rv;




More information about the Pcsclite-cvs-commit mailing list