diff --git a/callback_dispatcher.cc b/callback_dispatcher.cc index da1e209..3b82872 100644 --- a/callback_dispatcher.cc +++ b/callback_dispatcher.cc @@ -100,9 +100,8 @@ namespace pEp { PEP_STATUS status = PassphraseCache::messageToSend(passphrase_cache, Adapter::session()); // if the cache has no valid passphrase ask the app - if (status == PEP_PASSPHRASE_REQUIRED || status == PEP_WRONG_PASSPHRASE) { + if (status == PEP_PASSPHRASE_REQUIRED || status == PEP_WRONG_PASSPHRASE) semaphore.stop(); - } // the pEp engine must try again return status; diff --git a/test/Makefile b/test/Makefile index 574f0be..63a19d4 100644 --- a/test/Makefile +++ b/test/Makefile @@ -6,7 +6,7 @@ CXXFLAGS+=-I../ .PHONY=all, test_adapter, test_adapter_cxx, test_library -all: test_adapter test_adapter_cxx test_library test_passphrase_cache +all: test_adapter test_adapter_cxx test_library test_passphrase_cache test_semaphore test_adapter: test_adapter.cc ../libpEpAdapter.a @@ -16,6 +16,8 @@ test_library: test_library.cc ../libpEpAdapter.a test_passphrase_cache: test_passphrase_cache.cc ../libpEpAdapter.a +test_semaphore: test_semaphore.cc ../libpEpAdapter.a + clean: rm -vf test_adapter rm -rvf test_adapter.dSYM diff --git a/test/test_semaphore.cc b/test/test_semaphore.cc new file mode 100644 index 0000000..29c3889 --- /dev/null +++ b/test/test_semaphore.cc @@ -0,0 +1,35 @@ +#include +#include +#include +#include "Semaphore.hh" + +using namespace std; +using namespace pEp; + +int main() +{ + Semaphore semaphore; + + thread thread1([&](){ + cout << "1: before stop\n"; + semaphore.stop(); + cout << "1: now on stop\n"; + semaphore.try_wait(); + cout << "1: and on go again\n"; + semaphore.try_wait(); + cout << "1: keeping going\n"; + }); + + sleep(1); + + thread thread2([&](){ + cout << "2: setting go\n"; + semaphore.go(); + }); + + thread1.join(); + thread2.join(); + + return 0; +} +