From c349952198ccb76453367f4668b8ccd071459735 Mon Sep 17 00:00:00 2001 From: Edouard Tisserant Date: Tue, 29 Nov 2016 01:00:22 +0100 Subject: [PATCH] ENGINE-133 timeout in retrieve_next_sync_msg - now wrapped, with stubs in MultipEp.py --- src/pEpmodule.cc | 16 +++++++++++++++- src/sync_mixin.cc | 21 ++++++++++++++++----- src/sync_mixin.hh | 2 ++ test/multipEp.py | 7 +++++++ 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index de7db9b..33033d2 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -387,7 +387,21 @@ BOOST_PYTHON_MODULE(pEp) " partner identity of communication partner\n" " result -1: cancel, 0: accepted, 1: rejected\n" "\n" - "call to deliver the handshake result"); + "call to deliver the handshake result") + .def("setTimeout", &SyncMixIn::setTimeout, + "setTimeout(self, timeout)\n" + "\n" + " timeout timeout to wait for\n" + "\n" + "overwrite this method with code setting timeout timer") + .def("cancelTimeout", &SyncMixIn::cancelTimeout, + "cancelTimeout(self)\n" + "\n" + "overwrite this method with code canceling timeout timer") + .def("onTimeout", &SyncMixIn::onTimeout, + "onTimeout(self)\n" + "\n" + "call this method when timeout occurs"); // codecs diff --git a/src/sync_mixin.cc b/src/sync_mixin.cc index 6ee297d..89b9785 100644 --- a/src/sync_mixin.cc +++ b/src/sync_mixin.cc @@ -71,16 +71,20 @@ namespace pEp { jmp_buf SyncMixIn::env; jmp_buf SyncMixIn::env_timeout; void *SyncMixIn::_msg; + bool SyncMixIn::running_timeout = false; int SyncMixIn::inject_sync_msg(void *msg, void *management) { _msg = msg; int val = setjmp(env); if (!val){ - // call python timeout timer cancel - auto that = dynamic_cast< SyncMixIn_callback * >( - static_cast< SyncMixIn * > (management)); - that->cancelTimeout(); + if(running_timeout){ + // call python timeout timer cancel + auto that = dynamic_cast< SyncMixIn_callback * >( + static_cast< SyncMixIn * > (management)); + that->cancelTimeout(); + running_timeout = false; + } do_sync_protocol(session, management); } return 0; @@ -99,7 +103,9 @@ namespace pEp { auto that = dynamic_cast< SyncMixIn_callback * >( static_cast< SyncMixIn * > (management)); that->setTimeout(*timeout); + running_timeout = true; }else{ + running_timeout = false; // this will inject tiemout event return NULL; } @@ -125,7 +131,12 @@ namespace pEp { void SyncMixIn_callback::setTimeout(time_t timeout) { - call_method< void >(_self, "SetTimeout", timeout); + call_method< void >(_self, "setTimeout", timeout); + } + + void SyncMixIn_callback::cancelTimeout() + { + call_method< void >(_self, "cancelTimeout"); } } } diff --git a/src/sync_mixin.hh b/src/sync_mixin.hh index 0436cb0..19ae388 100644 --- a/src/sync_mixin.hh +++ b/src/sync_mixin.hh @@ -39,6 +39,7 @@ namespace pEp { static jmp_buf env; static jmp_buf env_timeout; + static bool running_timeout; static void *_msg; static int inject_sync_msg(void *msg, void *management); static void *retrieve_next_sync_msg(void *management, time_t *timeout); @@ -54,6 +55,7 @@ namespace pEp { void messageToSend(Message msg); void showHandshake(Identity me, Identity partner); void setTimeout(time_t timeout); + void cancelTimeout(); }; } } diff --git a/test/multipEp.py b/test/multipEp.py index 4adfca1..1971ce8 100644 --- a/test/multipEp.py +++ b/test/multipEp.py @@ -211,6 +211,13 @@ def pEp_instance_run(iname, _own_addresses, conn, _msgs_folders, _handshakes_see handshakes_seen.append(tw) printheader() + def setTimeout(self, timeout): + print("SET TIMEOUT :", timeout) + + def cancelTimeout(self): + print("CANCEL TIMEOUT !") + + handler = Handler() while True: