fix: query fresh state on timeout for Windows card events#116
Merged
Conversation
The previous timeout handler checked dwEventState from the timed-out SCardGetStatusChange call. On Windows, this value may just mirror dwCurrentState rather than reflecting actual hardware state, making the state divergence check ineffective. This fix explicitly queries fresh state using SCARD_STATE_UNAWARE when a timeout occurs, ensuring we detect card insert/remove events within ~1 second even when Windows PC/SC fails to set SCARD_STATE_CHANGED correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the remaining issue with Windows card events not firing reliably (#111).
Root cause: The timeout handler was checking
dwEventStatefrom the timed-outSCardGetStatusChangecall. On Windows, after a timeout,dwEventStatemay just mirrordwCurrentState(what was passed in) rather than reflecting the actual hardware state. This made the state divergence check ineffective.Fix: Explicitly query fresh state using
SCARD_STATE_UNAWAREwhen a timeout occurs. This ensures we get the real current hardware state and can detect missed card insert/remove events within ~1 second.Changes
reader_monitor.cppto query fresh state instead of relying on potentially staledwEventStateSCARD_STATE_UNAWAREwith zero timeout to force an immediate fresh state queryTest plan
Fixes #111