From 9f6ddb2b78c0fd2caa63695efdfc42ebedcecdef Mon Sep 17 00:00:00 2001 From: Bill Williams Date: Wed, 12 Dec 2018 14:23:10 -0800 Subject: [PATCH 1/2] change serviceAlivetask to a function call from main --- src/conn_interface.c | 15 ++++++++++++--- src/service_alive.c | 8 ++------ src/service_alive.h | 2 +- tests/test_conn_interface.c | 14 +++++++------- tests/test_service_alive.c | 5 ++++- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/conn_interface.c b/src/conn_interface.c index c0f841c..9259f5f 100644 --- a/src/conn_interface.c +++ b/src/conn_interface.c @@ -69,6 +69,7 @@ void createSocketConnection(void (* initKeypress)()) bool seshat_registered = false; unsigned int webpa_ping_timeout_ms = 1000 * get_parodus_cfg()->webpa_ping_timeout; unsigned int heartBeatTimer = 0; + struct timespec start_svc_alive_timer; //loadParodusCfg(tmpCfg,get_parodus_cfg()); #ifdef FEATURE_DNS_QUERY @@ -93,13 +94,13 @@ void createSocketConnection(void (* initKeypress)()) } packMetaData(); - UpStreamMsgQ = NULL; + UpStreamMsgQ = NULL; StartThread(handle_upstream); StartThread(processUpstreamMessage); ParodusMsgQ = NULL; StartThread(messageHandlerTask); - StartThread(serviceAliveTask); - StartThread(CRUDHandlerTask); + /* StartThread(serviceAliveTask); */ + StartThread(CRUDHandlerTask); if (NULL != initKeypress) { @@ -108,6 +109,8 @@ void createSocketConnection(void (* initKeypress)()) seshat_registered = __registerWithSeshat(); + clock_gettime(CLOCK_REALTIME, &start_svc_alive_timer); + do { struct timespec start, stop, diff; @@ -169,6 +172,12 @@ void createSocketConnection(void (* initKeypress)()) } createNopollConnection(ctx); } + clock_gettime(CLOCK_REALTIME, &stop); + timespec_diff(&start_svc_alive_timer, &stop, &diff); + if (diff.tv_sec >= 30) { + serviceAliveTask (); + start_svc_alive_timer.tv_sec += 30; + } } while(!get_close_retry() && !g_shutdown); close_and_unref_connection(get_global_conn()); diff --git a/src/service_alive.c b/src/service_alive.c index cb90a39..bacf55b 100644 --- a/src/service_alive.c +++ b/src/service_alive.c @@ -37,7 +37,7 @@ /* * @brief To handle registered services to indicate that the service is still alive. */ -void *serviceAliveTask() +int serviceAliveTask() { void *svc_bytes; wrp_msg_t svc_alive_msg; @@ -52,11 +52,10 @@ void *serviceAliveTask() if(nbytes < 0) { ParodusError(" Failed to encode wrp struct returns %d\n", nbytes); + return -1; } else { - while(1) - { ParodusPrint("serviceAliveTask: numOfClients registered is %d\n", get_numOfClients()); if(get_numOfClients() > 0) { @@ -92,14 +91,11 @@ void *serviceAliveTask() } } ParodusPrint("Waiting for 30s to send keep alive msg \n"); - sleep(KEEPALIVE_INTERVAL_SEC); } else { ParodusInfo("No clients are registered, waiting ..\n"); - sleep(50); } - } } return 0; } diff --git a/src/service_alive.h b/src/service_alive.h index 3298b04..e8b273a 100644 --- a/src/service_alive.h +++ b/src/service_alive.h @@ -32,7 +32,7 @@ extern "C" { #endif -void *serviceAliveTask(); +int serviceAliveTask(); #ifdef __cplusplus diff --git a/tests/test_conn_interface.c b/tests/test_conn_interface.c index 2c9d7ae..f4bcf0f 100644 --- a/tests/test_conn_interface.c +++ b/tests/test_conn_interface.c @@ -103,9 +103,9 @@ void *messageHandlerTask() return NULL; } -void *serviceAliveTask() +int serviceAliveTask() { - return NULL; + return 0; } int nopoll_loop_wait(noPollCtx * ctx,long timeout) @@ -224,7 +224,7 @@ void test_createSocketConnection() expect_function_call(createNopollConnection); expect_function_call(packMetaData); - expect_function_calls(StartThread, 5); + expect_function_calls(StartThread, 4); expect_function_call(initKeypress); will_return(nopoll_loop_wait, 1); expect_function_call(nopoll_loop_wait); @@ -260,7 +260,7 @@ void test_createSocketConnection1() expect_function_call(createNopollConnection); expect_function_call(packMetaData); - expect_function_calls(StartThread, 5); + expect_function_calls(StartThread, 4); will_return(nopoll_loop_wait, 1); expect_function_call(nopoll_loop_wait); @@ -310,7 +310,7 @@ void test_PingMissIntervalTime() expect_function_call(createNopollConnection); expect_function_call(packMetaData); - expect_function_calls(StartThread, 5); + expect_function_calls(StartThread, 4); //Increment ping interval time to 1 sec for each nopoll_loop_wait call will_return(nopoll_loop_wait, 1); will_return(nopoll_loop_wait, 1); @@ -351,7 +351,7 @@ void err_createSocketConnection() expect_function_call(createNopollConnection); expect_function_call(packMetaData); - expect_function_calls(StartThread, 5); + expect_function_calls(StartThread, 4); will_return(nopoll_loop_wait, 1); expect_function_call(nopoll_loop_wait); @@ -388,7 +388,7 @@ void test_createSocketConnection_cloud_disconn() expect_function_call(createNopollConnection); expect_function_call(packMetaData); - expect_function_calls(StartThread, 5); + expect_function_calls(StartThread, 4); will_return(nopoll_loop_wait, 1); expect_function_call(nopoll_loop_wait); diff --git a/tests/test_service_alive.c b/tests/test_service_alive.c index bb4735e..26ba5ed 100644 --- a/tests/test_service_alive.c +++ b/tests/test_service_alive.c @@ -134,7 +134,10 @@ static void *keep_alive_thread() //ParodusPrint("keep_alive threadId is %d\n", threadId); sleep(2); ParodusPrint("Starting serviceAliveTask..\n"); - serviceAliveTask(); + while (true) { + serviceAliveTask(); + sleep (30); + } return 0; } From 905cb3bade81197136ca1aa1800b1f568b9c3614 Mon Sep 17 00:00:00 2001 From: Bill Williams Date: Tue, 18 Dec 2018 13:39:25 -0800 Subject: [PATCH 2/2] update change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc2922f..33c3879 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - added NULL check for device mac id in upstream retrieve message handling - backoff retry to include find_servers in loop (connection.c) - backoff max is max count not max delay +- change svc alive from a thread to a function called every 30 sec from main ## [1.0.1] - 2018-07-18 ### Added