diff --git a/src/pcsclite.cpp b/src/pcsclite.cpp index 1c1c1c8..007cd09 100644 --- a/src/pcsclite.cpp +++ b/src/pcsclite.cpp @@ -22,7 +22,8 @@ void PCSCLite::init(Handle target) { PCSCLite::PCSCLite(): m_card_context(NULL), m_card_reader_state(), - m_status_thread(NULL) { + m_status_thread(NULL), + m_closing(false) { pthread_mutex_init(&m_mutex, NULL); @@ -91,7 +92,12 @@ NAN_METHOD(PCSCLite::Close) { PCSCLite* obj = ObjectWrap::Unwrap(args.This()); - LONG result = SCardCancel(obj->m_card_context); + LONG result = SCARD_S_SUCCESS; + if (obj->m_pnp) { + result = SCardCancel(obj->m_card_context); + } else { + obj->m_closing = true; + } NanReturnValue(NanNew(result)); } @@ -140,7 +146,7 @@ void* PCSCLite::HandlerFunction(void* arg) { AsyncBaton* async_baton = static_cast(arg); PCSCLite* pcsclite = async_baton->pcsclite; async_baton->async_result = new AsyncResult(); - while (result == SCARD_S_SUCCESS) { + while (!pcsclite->m_closing && (result == SCARD_S_SUCCESS)) { /* Lock mutex. It'll be unlocked after the callback has been sent */ pthread_mutex_lock(&pcsclite->m_mutex); /* Get card readers */ diff --git a/src/pcsclite.h b/src/pcsclite.h index 582a5e0..7651ac6 100644 --- a/src/pcsclite.h +++ b/src/pcsclite.h @@ -53,6 +53,7 @@ class PCSCLite: public node::ObjectWrap { pthread_t m_status_thread; pthread_mutex_t m_mutex; bool m_pnp; + bool m_closing; }; #endif /* PCSCLITE_H */