Merge pull request #267 from bill1600/untask_svc_alive

change serviceAlivetask to a function call from main
This commit is contained in:
shilpa24balaji
2018-12-18 14:09:17 -08:00
committed by GitHub
6 changed files with 27 additions and 18 deletions

View File

@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- backoff max is max count not max delay
- used mutex protection to make client list and nn_sends thread safe
- put mutex lock into get_global_node
- change svc alive from a thread to a function called every 30 sec from main
## [1.0.1] - 2018-07-18
### Added

View File

@@ -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());

View File

@@ -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());
temp = get_global_node();
if(get_numOfClients() > 0)
@@ -93,15 +92,12 @@ void *serviceAliveTask()
}
release_global_node ();
ParodusPrint("Waiting for 30s to send keep alive msg \n");
sleep(KEEPALIVE_INTERVAL_SEC);
}
else
{
release_global_node ();
ParodusInfo("No clients are registered, waiting ..\n");
sleep(50);
}
}
}
return 0;
}

View File

@@ -32,7 +32,7 @@
extern "C" {
#endif
void *serviceAliveTask();
int serviceAliveTask();
#ifdef __cplusplus

View File

@@ -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);

View File

@@ -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;
}