src: fix PCSCLite.close() for OS X

This commit is contained in:
Santiago Gimeno
2014-09-26 12:06:27 +02:00
parent 674df70a74
commit c5602733a4
2 changed files with 10 additions and 3 deletions

View File

@@ -22,7 +22,8 @@ void PCSCLite::init(Handle<Object> target) {
PCSCLite::PCSCLite(): m_card_context(NULL), PCSCLite::PCSCLite(): m_card_context(NULL),
m_card_reader_state(), m_card_reader_state(),
m_status_thread(NULL) { m_status_thread(NULL),
m_closing(false) {
pthread_mutex_init(&m_mutex, NULL); pthread_mutex_init(&m_mutex, NULL);
@@ -91,7 +92,12 @@ NAN_METHOD(PCSCLite::Close) {
PCSCLite* obj = ObjectWrap::Unwrap<PCSCLite>(args.This()); PCSCLite* obj = ObjectWrap::Unwrap<PCSCLite>(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<Integer>(result)); NanReturnValue(NanNew<Integer>(result));
} }
@@ -140,7 +146,7 @@ void* PCSCLite::HandlerFunction(void* arg) {
AsyncBaton* async_baton = static_cast<AsyncBaton*>(arg); AsyncBaton* async_baton = static_cast<AsyncBaton*>(arg);
PCSCLite* pcsclite = async_baton->pcsclite; PCSCLite* pcsclite = async_baton->pcsclite;
async_baton->async_result = new AsyncResult(); 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 */ /* Lock mutex. It'll be unlocked after the callback has been sent */
pthread_mutex_lock(&pcsclite->m_mutex); pthread_mutex_lock(&pcsclite->m_mutex);
/* Get card readers */ /* Get card readers */

View File

@@ -53,6 +53,7 @@ class PCSCLite: public node::ObjectWrap {
pthread_t m_status_thread; pthread_t m_status_thread;
pthread_mutex_t m_mutex; pthread_mutex_t m_mutex;
bool m_pnp; bool m_pnp;
bool m_closing;
}; };
#endif /* PCSCLITE_H */ #endif /* PCSCLITE_H */