Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: migrate pthreads to uv_threads #24

Closed
wants to merge 7 commits into from
Closed

Conversation

santigimeno
Copy link
Owner

  • So it can be compatible in every platform supported by libuv.
  • Use attached threads instead of detached.
  • Remove all CardReader 'status' listeners before emitting the
    'end' event.

@oliversalzburg
Copy link

This is what I get when trying to build on Windows: https://gist.github.com/oliversalzburg/450e114fbb371b32acd7

So, yeah, it seems like the threads are no longer a problem, now snprintf is :P

@santigimeno
Copy link
Owner Author

@oliversalzburg thanks for the report! Can you try again?

@oliversalzburg
Copy link

Only 2 errors left:

..\src\pcsclite.cpp(46): error C3861: 'pcsc_stringify_error': identifier not found [d:\temp\node-pcsclite\build\pcsclite.vcxproj]
..\src\pcsclite.cpp(192): error C3861: 'sleep': identifier not found [d:\temp\node-pcsclite\build\pcsclite.vcxproj]

@santigimeno
Copy link
Owner Author

@oliversalzburg I think those are fixed now

@LudovicRousseau
Copy link
Contributor

Build and works on Mac OS X.

@oliversalzburg
Copy link

Yep, building works on Windows. I can't functionally test anything here at home though :)

@oliversalzburg
Copy link

When I run example.js on Windows, I get an infinite loop of this:

New reader detected OMNIKEY CardMan 5x21 0
New reader detected OMNIKEY CardMan 5x21-CL 0
Status( OMNIKEY CardMan 5x21 0 ): { state: 18, atr: <SlowBuffer > }
card removed
Disconnected
New reader detected OMNIKEY CardMan 5x21 0
New reader detected OMNIKEY CardMan 5x21-CL 0
Status( OMNIKEY CardMan 5x21-CL 0 ): { state: 18, atr: <SlowBuffer > }
card removed
Disconnected
Status( OMNIKEY CardMan 5x21 0 ): { state: 18, atr: <SlowBuffer > }
card removed
Disconnected
Status( OMNIKEY CardMan 5x21-CL 0 ): { state: 18, atr: <SlowBuffer > }
card removed
Disconnected

@santigimeno
Copy link
Owner Author

Two things:

  • When you build the module, are you receiving any warnings? If so, can you paste them?
  • How many readers do you have connected? Any of them have a card inserted?

Thanks!

@oliversalzburg
Copy link

I updated my build log here: https://gist.github.com/oliversalzburg/450e114fbb371b32acd7 There are some warnings.

The device I have connected registers as 2 readers, no cards are inserted.

@santigimeno
Copy link
Owner Author

The problem could be this:

\?PnP?\Notification and reader count

The documentation states: rgReaderStates - 'To be notified of the arrival of a new smart card reader, set the szReader member of a SCARD_READERSTATE structure to "\\\\?PnP?\\Notification", and set all of the other members of that structure to zero.'

It seems that the high word of the dwCurrentState member of the SCARD_READERSTATE structure must also contain the count of currently attached readers otherwise SCardGetStatusChange returns immediately.


e.g. If one reader is already attached, the value can be set with:

DWORD
currentReaderCount
= 1;
monitorReadersState.dwCurrentState = (currentReaderCount << 16);

Taken from the community additions @ http://msdn.microsoft.com/en-us/library/windows/desktop/aa379773%28v=vs.85%29.aspx

@LudovicRousseau
Copy link
Contributor

http://pcsclite.alioth.debian.org/api/group__API.html#ga33247d5d1257d59e55647c3bb717db24

dwEventState also contains a number of events in the upper 16 bits (dwEventState & 0xFFFF0000). This number of events is incremented for each card insertion or removal in the specified reader.

This can be used to detect a card removal/insertion between two calls to SCardGetStatusChange()

You need to make a 1st call to SCardGetStatusChange() to get the current values in dwEventState. Then copy dwEventState in dwCurrentState to be notified when something changes.

I was not aware that for the \\?PnP?\Notification special reader this number was the number of readers. I will try to add that in pcsc-lite. I opened a feature request at https://alioth.debian.org/tracker/index.php?func=detail&aid=314834&group_id=30105&atid=410088

@santigimeno
Copy link
Owner Author

Yes, I was doing that copy when checking status in CardReader but not when checking the \\?PnP?\Notification in PCSCLite. I'll update the PR accordingly.
Thanks for the explanation

@santigimeno
Copy link
Owner Author

@oliversalzburg can you try again?

@oliversalzburg
Copy link

@santigimeno Much better, but still a bit confusing:

$ node examples/example.js
New reader detected OMNIKEY CardMan 5x21 0
New reader detected OMNIKEY CardMan 5x21-CL 0
Status( OMNIKEY CardMan 5x21 0 ): { state: 18, atr: <SlowBuffer > }
card removed
Disconnected
Status( OMNIKEY CardMan 5x21-CL 0 ): { state: 18, atr: <SlowBuffer > }
card removed
Disconnected
Status( OMNIKEY CardMan 5x21-CL 0 ): { state: 65570,
  atr: <SlowBuffer 3b 8f 80 01 80 4f 0c a0 00 00 03 06 03 00 01 00 00 00 00 6a> }
card inserted
Protocol( OMNIKEY CardMan 5x21-CL 0 ): 2
Status( OMNIKEY CardMan 5x21-CL 0 ): { state: 65826,
  atr: <SlowBuffer 3b 8f 80 01 80 4f 0c a0 00 00 03 06 03 00 01 00 00 00 00 6a> }
[Error: SCardTransmit error: (0x0000001f)]
Status( OMNIKEY CardMan 5x21-CL 0 ): { state: 131090, atr: <SlowBuffer > }
card removed
Disconnected

I don't understand the first "card removed" events right after I start the application.

I then put one card onto the reader and removed it after a couple of seconds, I don't know if the output is to be expected.

Looks pretty good overall though. Nice.

@santigimeno
Copy link
Owner Author

@oliversalzburg Yeah, the example could be improved. In this case it just means that there's no card inserted in the reader.
Other than that the output looks correct. I don't know what the 0x0000001f SCardTransmit error means though.

@santigimeno
Copy link
Owner Author

@oliversalzburg On a second thought, it seems to me that the transmit(SCardTransmit) call was blocked and didn't returned until you removed the card. I'm experiencing similar issues with OMNIKEY readers myself. Can you confirm this?

@oliversalzburg
Copy link

@santigimeno The error is emitted right after connecting the card.

@santigimeno
Copy link
Owner Author

Ok. Then it simply looks like the SCardTransmit failed.

- So it can be compatible in every platform supported by libuv.
- Use attached threads instead of detached.
- Remove all CardReader 'status' listeners before emitting the
  'end' event.
@santigimeno santigimeno mentioned this pull request Apr 8, 2015
@santigimeno
Copy link
Owner Author

Already merged in master and published in version 0.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants