diff --git a/libretroshare/src/retroshare/rstokenservice.h b/libretroshare/src/retroshare/rstokenservice.h index a7da6ee32..e48df29ad 100644 --- a/libretroshare/src/retroshare/rstokenservice.h +++ b/libretroshare/src/retroshare/rstokenservice.h @@ -232,7 +232,8 @@ public: RsTokenService::GxsRequestStatus waitToken( uint32_t token, std::chrono::milliseconds maxWait = std::chrono::milliseconds(500), - std::chrono::milliseconds checkEvery = std::chrono::milliseconds(2)) + std::chrono::milliseconds checkEvery = std::chrono::milliseconds(2), + bool auto_delete_if_unsuccessful=true) { #if defined(__ANDROID__) && (__ANDROID_API__ < 24) auto wkStartime = std::chrono::steady_clock::now(); @@ -241,12 +242,13 @@ LLwaitTokenBeginLabel: #endif auto timeout = std::chrono::steady_clock::now() + maxWait; auto st = requestStatus(token); - while( !(st == RsTokenService::FAILED || st >= RsTokenService::COMPLETE) - && std::chrono::steady_clock::now() < timeout ) + while( !(st == RsTokenService::FAILED || st >= RsTokenService::COMPLETE) && std::chrono::steady_clock::now() < timeout ) { std::this_thread::sleep_for(checkEvery); st = requestStatus(token); } + if(st != RsTokenService::COMPLETE && auto_delete_if_unsuccessful) + cancelRequest(token); #if defined(__ANDROID__) && (__ANDROID_API__ < 24) /* Work around for very slow/old android devices, we don't expect this