src: fix reader disconnection logic

- A reader disconnection can't be detected by SCardGetStatusChange in the reader
  (cardreader.cpp) but by detecting that the reader doesn't appear in the list of
  readers retrieved in pcsclite.cpp.
- The list of readers is now stored in an object where the keys are the names of
  the readers. When a reader disconnection is detected, the reader is closed
  triggering the 'end' event. Then the reader is removed from the readers list.
This commit is contained in:
Santiago Gimeno
2015-09-23 12:41:37 +02:00
parent 8f3309520d
commit 0a3eaafb2b
2 changed files with 20 additions and 15 deletions

View File

@@ -383,10 +383,7 @@ void CardReader::HandlerFunction(void* arg) {
while (keep_watching) {
result = SCardGetStatusChange(reader->m_status_card_context, INFINITE, &card_reader_state, 1);
keep_watching = ((result == SCARD_S_SUCCESS) &&
(!reader->m_state) &&
(!((card_reader_state.dwEventState & SCARD_STATE_UNKNOWN) ||
(card_reader_state.dwEventState & SCARD_STATE_UNAVAILABLE))));
keep_watching = (result == SCARD_S_SUCCESS) && (!reader->m_state);
uv_mutex_lock(&reader->m_mutex);
if (reader->m_state == 1) {