From 17309629889269e99d14b4e880675682d8b6435f Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 11 Dec 2017 10:51:53 +0100 Subject: Allow to execute client-supplied function on each retry and cancel with it Signed-off-by: Szczepan Zalega --- include/device_proto.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/device_proto.h') diff --git a/include/device_proto.h b/include/device_proto.h index 388c721..89fed12 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -1,6 +1,7 @@ #ifndef DEVICE_PROTO_H #define DEVICE_PROTO_H +#include #include #include #include @@ -38,6 +39,8 @@ namespace nitrokey { namespace proto { extern std::mutex send_receive_mtx; + using retry_type = std::function ; + extern retry_type on_retry; /* @@ -362,6 +365,8 @@ namespace nitrokey { dev->m_counters.total_retries++; LOG(".", Loglevel::DEBUG_L1); std::this_thread::sleep_for(retry_timeout); + if (on_retry(receiving_retry_counter) == -1) + throw DeviceReceivingFailure("User canceled"); continue; } if (successful_communication) break; -- cgit v1.2.3