diff --git a/weaver/libese_weaver/transport/include/SessionTimer.h b/weaver/libese_weaver/transport/include/SessionTimer.h index 3f33690..484b6ba 100644 --- a/weaver/libese_weaver/transport/include/SessionTimer.h +++ b/weaver/libese_weaver/transport/include/SessionTimer.h @@ -43,6 +43,7 @@ class Timer { // Start the timer with the specified timeout and call closeChannel if timeout is reached void start(int timeout_ms, void* ptr) { + int final_timeout = 0; if (!is_running) { is_running = true; #ifdef OMAPI_TRANSPORT @@ -56,7 +57,11 @@ class Timer { return; } - if (alarm(timeout_ms / 1000) != 0) { + if (timeout_ms >= remaining) final_timeout = timeout_ms; + else final_timeout = remaining; + + LOG(DEBUG) << "Start with final_timeout: " << final_timeout; + if (alarm(final_timeout / 1000) != 0) { LOG(ERROR) << "Error setting the alarm. " << std::endl; return; } @@ -67,12 +72,14 @@ class Timer { void stop() { if (is_running) { is_running = false; - alarm(0); + remaining = alarm(0) * 1000; + LOG(DEBUG) << "Stop remaining time: " << remaining; } } private: std::atomic is_running; + int remaining = 0; #ifdef OMAPI_TRANSPORT static void* transport_ptr; #else