Skip to content

Commit

Permalink
transaction: Implement Card::reconnect() wrapper
Browse files Browse the repository at this point in the history
This gives us access to Card::reconnect() from within a transaction so
that we can check the card status and reset it conditionally with no
interference from other processes.

This fixes a race condition I had between two processes where both
processes passed the status check resulting in two card resets.

Signed-off-by: Konrad Vité <[email protected]>
  • Loading branch information
kgraefe authored and bluetech committed Dec 13, 2024
1 parent f2cd1ba commit 3d0dd9b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pcsc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,21 @@ impl<'tx> Transaction<'tx> {
Ok(())
}
}

/// Reconnect to the card.
///
/// This function wraps `SCardReconnect` ([pcsclite][1], [MSDN][2]).
///
/// [1]: https://pcsclite.apdu.fr/api/group__API.html#gad5d4393ca8c470112ad9468c44ed8940
/// [2]: https://msdn.microsoft.com/en-us/library/aa379797.aspx
pub fn reconnect(
&mut self,
share_mode: ShareMode,
preferred_protocols: Protocols,
initialization: Disposition,
) -> Result<(), Error> {
self.card.reconnect(share_mode, preferred_protocols, initialization)
}
}

impl<'tx> Drop for Transaction<'tx> {
Expand Down

0 comments on commit 3d0dd9b

Please sign in to comment.