[Pcsclite-git-commit] [CCID] 01/05: OpenUSBByName(): add more time on Mac OS X

Ludovic Rousseau rousseau at moszumanska.debian.org
Wed Sep 16 16:31:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

rousseau pushed a commit to branch master
in repository CCID.

commit 690e90f476c3815c31874e523ba017f7f1d372cd
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date:   Wed Sep 16 10:31:55 2015 +0200

    OpenUSBByName(): add more time on Mac OS X
    
    The change in 0a295238204b8aef683fa5e69187b1060210f487 (svn revision
    6890) was not enough.  Some readers (like SafeNet eToken 7300) need
    more than 100 ms to be available at the libusb level.
    
    The code now:
    - waits for 100 ms only if the reader is not found. No more performance
      impact in "normal" situations
    - loops up to 10 times before returning an error
    
    The maximum waiting time is now 10 x 100 ms = 1 second. It should be
    enough even with slow readers and slow computers.
---
 src/ccid_usb.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/ccid_usb.c b/src/ccid_usb.c
index b3d6721..cae44ef 100644
--- a/src/ccid_usb.c
+++ b/src/ccid_usb.c
@@ -221,6 +221,7 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
 #else
 	/* 100 ms delay */
 	struct timespec sleep_time = { 0, 100 * 1000 * 1000 };
+	int count_libusb = 10;
 #endif
 	int interface_number = -1;
 	int i;
@@ -314,8 +315,7 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
 	}
 
 #ifdef __APPLE__
-	/* give some time to libusb to detect the new USB devices on Mac OS X */
-	nanosleep(&sleep_time, NULL);
+again_libusb:
 #endif
 	cnt = libusb_get_device_list(ctx, &devs);
 	if (cnt < 0)
@@ -697,6 +697,20 @@ again:
 end:
 	if (usbDevice[reader_index].dev_handle == NULL)
 	{
+#ifdef __APPLE__
+		/* give some time to libusb to detect the new USB devices on Mac OS X */
+		if (count_libusb > 0)
+		{
+			count_libusb--;
+			DEBUG_INFO2("Wait after libusb: %d", count_libusb);
+			nanosleep(&sleep_time, NULL);
+
+			/* free the libusb allocated list & devices */
+			libusb_free_device_list(devs, 1);
+
+			goto again_libusb;
+		}
+#endif
 		close_libusb_if_needed();
 		if (claim_failed)
 			return STATUS_COMM_ERROR;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/CCID.git



More information about the Pcsclite-cvs-commit mailing list