[Pcsclite-cvs-commit] r3103 - in /trunk/PCSC/src: eventhandler.c winscard.c winscard_clnt.c
rousseau at users.alioth.debian.org
rousseau at users.alioth.debian.org
Tue Aug 26 09:24:21 UTC 2008
Author: rousseau
Date: Tue Aug 26 09:24:20 2008
New Revision: 3103
URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=3103
Log:
use asynchronous events instead of polling for SCardGetStatusChange()
on client side use WaitForPcscdEvent() instead of
SYS_USleep(PCSCLITE_STATUS_WAIT)
on server side use StatSynchronize() instead of SYS_MMapSynchronize()
Modified:
trunk/PCSC/src/eventhandler.c
trunk/PCSC/src/winscard.c
trunk/PCSC/src/winscard_clnt.c
Modified: trunk/PCSC/src/eventhandler.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/eventhandler.c?rev=3103&op=diff
==============================================================================
--- trunk/PCSC/src/eventhandler.c (original)
+++ trunk/PCSC/src/eventhandler.c Tue Aug 26 09:24:20 2008
@@ -35,6 +35,7 @@
#include "ifdwrapper.h"
#include "prothandler.h"
#include "strlcpycat.h"
+#include "utils.h"
static PREADER_STATE readerStates[PCSCLITE_MAX_READERS_CONTEXTS];
@@ -234,7 +235,6 @@
DWORD dwStatus, dwReaderSharing;
DWORD dwCurrentState;
DWORD dwAtrLen;
- int pageSize;
/*
* Zero out everything
@@ -244,8 +244,6 @@
dwCurrentState = 0;
lpcReader = rContext->lpcReader;
-
- pageSize = SYS_GetPageSize();
dwAtrLen = rContext->readerState->cardAtrLength;
rv = IFDStatusICC(rContext, &dwStatus, rContext->readerState->cardAtr,
@@ -318,7 +316,7 @@
rContext->readerState->readerSharing = dwReaderSharing =
rContext->dwContexts;
- SYS_MMapSynchronize((void *) rContext->readerState, pageSize);
+ StatSynchronize(rContext->readerState);
while (1)
{
@@ -350,7 +348,7 @@
dwCurrentState = SCARD_UNKNOWN;
- SYS_MMapSynchronize((void *) rContext->readerState, pageSize);
+ StatSynchronize(rContext->readerState);
/*
* This code causes race conditions on G4's with USB
@@ -400,7 +398,7 @@
incrementEventCounter(rContext->readerState);
- SYS_MMapSynchronize((void *) rContext->readerState, pageSize);
+ StatSynchronize(rContext->readerState);
}
}
@@ -447,7 +445,7 @@
incrementEventCounter(rContext->readerState);
- SYS_MMapSynchronize((void *) rContext->readerState, pageSize);
+ StatSynchronize(rContext->readerState);
Log2(PCSC_LOG_INFO, "Card inserted into %s", lpcReader);
@@ -475,7 +473,7 @@
{
dwReaderSharing = rContext->dwContexts;
rContext->readerState->readerSharing = dwReaderSharing;
- SYS_MMapSynchronize((void *) rContext->readerState, pageSize);
+ StatSynchronize(rContext->readerState);
}
if (rContext->pthCardEvent)
Modified: trunk/PCSC/src/winscard.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard.c?rev=3103&op=diff
==============================================================================
--- trunk/PCSC/src/winscard.c (original)
+++ trunk/PCSC/src/winscard.c Tue Aug 26 09:24:20 2008
@@ -494,7 +494,7 @@
* Propagate new state to Shared Memory
*/
rContext->readerState->readerSharing = rContext->dwContexts;
- SYS_MMapSynchronize((void *) rContext->readerState, SYS_GetPageSize() );
+ StatSynchronize(rContext->readerState);
PROFILE_END
@@ -791,7 +791,7 @@
* Propagate new state to Shared Memory
*/
rContext->readerState->readerSharing = rContext->dwContexts;
- SYS_MMapSynchronize((void *) rContext->readerState, SYS_GetPageSize() );
+ StatSynchronize(rContext->readerState);
return SCARD_S_SUCCESS;
}
@@ -974,7 +974,7 @@
* Propagate new state to Shared Memory
*/
rContext->readerState->readerSharing = rContext->dwContexts;
- SYS_MMapSynchronize((void *) rContext->readerState, SYS_GetPageSize() );
+ StatSynchronize(rContext->readerState);
return SCARD_S_SUCCESS;
}
Modified: trunk/PCSC/src/winscard_clnt.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_clnt.c?rev=3103&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_clnt.c (original)
+++ trunk/PCSC/src/winscard_clnt.c Tue Aug 26 09:24:20 2008
@@ -27,6 +27,7 @@
#include <sys/un.h>
#include <errno.h>
#include <stddef.h>
+#include <sys/time.h>
#include "misc.h"
#include "pcscd.h"
@@ -1778,12 +1779,56 @@
* printf("reader state: 0x%04X\n", rgReaderStates[1].dwEventState);
* @endcode
*/
+static long WaitForPcscdEvent(long dwTime)
+{
+ char filename[FILENAME_MAX];
+ char buf[1];
+ int fd;
+ struct timeval tv, *ptv = NULL;
+ struct timeval before, after;
+ fd_set read_fd;
+
+ if (INFINITE != dwTime)
+ {
+ if (dwTime < 0)
+ return 0;
+ gettimeofday(&before, NULL);
+ tv.tv_sec = dwTime/1000;
+ tv.tv_usec = dwTime*1000 - tv.tv_sec*1000000;
+ ptv = &tv;
+ }
+
+ snprintf(filename, sizeof(filename), "%s/event.%d.%d", PCSCLITE_EVENTS_DIR,
+ SYS_GetPID(), SYS_RandomInt(0, 0x10000));
+ mkfifo(filename, 0644);
+ fd = SYS_OpenFile(filename, O_RDONLY | O_NONBLOCK, 0);
+
+ FD_ZERO(&read_fd);
+ FD_SET(fd, &read_fd);
+
+ select(fd+1, &read_fd, NULL, NULL, ptv);
+
+ SYS_ReadFile(fd, buf, 1);
+ SYS_CloseFile(fd);
+
+ if (INFINITE != dwTime)
+ {
+ long int diff;
+
+ gettimeofday(&after, NULL);
+ diff = time_sub(&after, &before);
+ dwTime -= diff/1000;
+ }
+
+ return dwTime;
+}
+
LONG SCardGetStatusChange(SCARDCONTEXT hContext, DWORD dwTimeout,
LPSCARD_READERSTATE_A rgReaderStates, DWORD cReaders)
{
PSCARD_READERSTATE_A currReader;
PREADER_STATE rContext;
- DWORD dwTime = 0;
+ long dwTime = dwTimeout;
DWORD dwState;
DWORD dwBreakFlag = 0;
int j;
@@ -1871,13 +1916,10 @@
goto end;
}
- SYS_USleep(PCSCLITE_STATUS_WAIT);
-
+ dwTime = WaitForPcscdEvent(dwTime);
if (dwTimeout != INFINITE)
{
- dwTime += PCSCLITE_STATUS_WAIT;
-
- if (dwTime >= (dwTimeout * 1000))
+ if (dwTime <= 0)
{
rv = SCARD_E_TIMEOUT;
goto end;
@@ -2173,21 +2215,20 @@
== psContextMap[dwContextIndex].contextBlockStatus)
break;
+ /* Only sleep once for each cycle of reader checks. */
+ dwTime = WaitForPcscdEvent(dwTime);
+
if (dwTimeout != INFINITE)
{
/* If time is greater than timeout and all readers have been
* checked
*/
- if (dwTime >= (dwTimeout * 1000))
+ if (dwTime <= 0)
{
rv = SCARD_E_TIMEOUT;
goto end;
}
}
-
- /* Only sleep once for each cycle of reader checks. */
- SYS_USleep(PCSCLITE_STATUS_WAIT);
- dwTime += PCSCLITE_STATUS_WAIT;
}
}
while (1);
More information about the Pcsclite-cvs-commit
mailing list