Skip to content

Commit 9883932

Browse files
committed
transaction: Implement Card::reconnect() wrapper
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]>
1 parent f2cd1ba commit 9883932

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pcsc/src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,21 @@ impl<'tx> Transaction<'tx> {
16841684
Ok(())
16851685
}
16861686
}
1687+
1688+
/// Reconnect to the card.
1689+
///
1690+
/// This function wraps `SCardReconnect` ([pcsclite][1], [MSDN][2]).
1691+
///
1692+
/// [1]: https://pcsclite.apdu.fr/api/group__API.html#gad5d4393ca8c470112ad9468c44ed8940
1693+
/// [2]: https://msdn.microsoft.com/en-us/library/aa379797.aspx
1694+
pub fn reconnect(
1695+
&mut self,
1696+
share_mode: ShareMode,
1697+
preferred_protocols: Protocols,
1698+
initialization: Disposition,
1699+
) -> Result<(), Error> {
1700+
self.card.reconnect(share_mode, preferred_protocols, initialization)
1701+
}
16871702
}
16881703

16891704
impl<'tx> Drop for Transaction<'tx> {

0 commit comments

Comments
 (0)