Browse Source

ENGINE-133 timeout in retrieve_next_sync_msg - now wrapped, with stubs in MultipEp.py

PYADPT-55
Edouard Tisserant 9 years ago
parent
commit
c349952198
  1. 16
      src/pEpmodule.cc
  2. 21
      src/sync_mixin.cc
  3. 2
      src/sync_mixin.hh
  4. 7
      test/multipEp.py

16
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

21
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");
}
}
}

2
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();
};
}
}

7
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:

Loading…
Cancel
Save