From d52ce946b0fc70f8f445e743fdca7a0f986a8358 Mon Sep 17 00:00:00 2001 From: Litvinov Alexander <2720927+you-think-you-are-special@users.noreply.github.com> Date: Thu, 18 Jul 2019 12:52:56 +0300 Subject: [PATCH] Add ksnetEvMgrInitialize --- src/ev_mgr.c | 28 ++++++++++++++++++++++++++++ src/ev_mgr.h | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/ev_mgr.c b/src/ev_mgr.c index b1436f020..13a2f2cbd 100644 --- a/src/ev_mgr.c +++ b/src/ev_mgr.c @@ -429,6 +429,34 @@ int ksnetEvMgrRun(ksnetEvMgrClass *ke) { return 0; } +void ksnetEvMgrInitialize(ksnetEvMgrClass *ke){ + ke->timer_val = 0; + ke->idle_count = 0; + ke->idle_activity_count = 0; + + if(!modules_init(ke)){ + ksnetEvMgrFree(ke, 0); // Free class variables and watchers after run + exit(EXIT_FAILURE); + } + + // Initialize idle watchers + ev_idle_init (&ke->idle_w, idle_cb); + ke->idle_w.data = ke->kc; + + // Initialize Check activity watcher + ev_idle_init (&ke->idle_activity_w, idle_activity_cb); + ke->idle_activity_w.data = ke; + + // Initialize and start main timer watcher, it is a repeated timer + ev_timer_init (&ke->timer_w, timer_cb, 0.0, KSNET_EVENT_MGR_TIMER); + ke->timer_w.data = ke; + ev_timer_start (ke->ev_loop, &ke->timer_w); + + // Run event loop + ke->runEventMgr = 1; +} + + /** * Free ksnetEvMgrClass after run * diff --git a/src/ev_mgr.h b/src/ev_mgr.h index caa2dca6b..c5d1fd6ac 100644 --- a/src/ev_mgr.h +++ b/src/ev_mgr.h @@ -368,7 +368,7 @@ const char *teoGetAppVersion(ksnetEvMgrClass *ke); int remove_peer_addr(ksnetEvMgrClass *ke, __CONST_SOCKADDR_ARG addr); int ksnetAllowAckEvent(ksnetEvMgrClass* ke, int allow); - +void ksnetEvMgrInitialize(ksnetEvMgrClass *ke); #ifdef __cplusplus }