changeset 4600:529910e1e1d2

6963006: Javacard exception when trying to access card during read operation Reviewed-by: valeriep
author miroslawzn
date Thu, 15 Sep 2011 13:26:33 -0700
parents ebef72df4b3e
children fb110f661e8c
files src/share/classes/sun/security/smartcardio/TerminalImpl.java
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/security/smartcardio/TerminalImpl.java	Thu Sep 15 16:46:30 2011 +0100
+++ b/src/share/classes/sun/security/smartcardio/TerminalImpl.java	Thu Sep 15 13:26:33 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -112,14 +112,17 @@
             if (wantPresent == present) {
                 return true;
             }
-            // no match, wait
-            status = SCardGetStatusChange(contextId, timeout, status, readers);
-            present = (status[0] & SCARD_STATE_PRESENT) != 0;
-            // should never happen
-            if (wantPresent != present) {
-                throw new CardException("wait mismatch");
+            // no match, wait (until timeout expires)
+            long end = System.currentTimeMillis() + timeout;
+            while (wantPresent != present && timeout != 0) {
+              // set remaining timeout
+              if (timeout != TIMEOUT_INFINITE) {
+                timeout = Math.max(end - System.currentTimeMillis(), 0l);
+              }
+              status = SCardGetStatusChange(contextId, timeout, status, readers);
+              present = (status[0] & SCARD_STATE_PRESENT) != 0;
             }
-            return true;
+            return wantPresent == present;
         } catch (PCSCException e) {
             if (e.code == SCARD_E_TIMEOUT) {
                 return false;