Skip to content

Commit

Permalink
fix: avoid endless loop when SCardEstablishContext is not successful
Browse files Browse the repository at this point in the history
  • Loading branch information
esskar committed Sep 13, 2024
1 parent 8100373 commit 1064d82
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pokusew/pcsclite",
"version": "0.6.0",
"version": "0.6.1",
"description": "Bindings over PC/SC to access Smart Cards",
"keywords": [
"nfc",
Expand Down
7 changes: 6 additions & 1 deletion src/pcsclite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ PCSCLite::PCSCLite(): m_card_context(0),

LONG result;
// TODO: consider removing this do-while Windows workaround that should not be needed anymore
INT retry = 0;
do {
if (retry > 0) {
Sleep(100 * retry);
}

// TODO: make dwScope (now hard-coded to SCARD_SCOPE_SYSTEM) customisable
result = SCardEstablishContext(SCARD_SCOPE_SYSTEM,
NULL,
NULL,
&m_card_context);
} while(result == SCARD_E_NO_SERVICE || result == SCARD_E_SERVICE_STOPPED);
} while((result == SCARD_E_NO_SERVICE || result == SCARD_E_SERVICE_STOPPED) && retry++ < 3);
if (result != SCARD_S_SUCCESS) {
Nan::ThrowError(error_msg("SCardEstablishContext", result).c_str());
} else {
Expand Down

0 comments on commit 1064d82

Please sign in to comment.