From f26c27d8338d89af61fc9877773e9926e9fa0b05 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 16 Nov 2020 22:09:50 -0300 Subject: [PATCH] Adding background task counter. --- src/core/iocalls.c | 3 ++- src/core/properties/unsigned.c | 5 +++++ src/core/session.c | 17 ++++++++++++++++- src/include/internals.h | 1 + src/include/lib3270/properties.h | 10 ++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/core/iocalls.c b/src/core/iocalls.c index 4a091dd..9d382ce 100644 --- a/src/core/iocalls.c +++ b/src/core/iocalls.c @@ -465,9 +465,10 @@ LIB3270_EXPORT int lib3270_run_task(H3270 *hSession, int(*callback)(H3270 *h, vo CHECK_SESSION_HANDLE(hSession); hSession->cbk.set_timer(hSession,1); + hSession->tasks++; rc = run_task(hSession,callback,parm); hSession->cbk.set_timer(hSession,0); - + hSession->tasks--; return rc; } diff --git a/src/core/properties/unsigned.c b/src/core/properties/unsigned.c index 535112d..9ad74f8 100644 --- a/src/core/properties/unsigned.c +++ b/src/core/properties/unsigned.c @@ -198,3 +198,8 @@ int lib3270_set_uint_property(H3270 *hSession, const char *name, unsigned int va } +LIB3270_EXPORT unsigned int lib3270_get_task_count(const H3270 *h) +{ + return h->tasks; +} + diff --git a/src/core/session.c b/src/core/session.c index 3e38588..c7ef5c9 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -67,9 +67,24 @@ void lib3270_session_free(H3270 *h) if(!h) return; - // Terminate session if(lib3270_is_connected(h)) + { + // Connected, disconnect lib3270_disconnect(h); + } + else if(lib3270_get_connection_state(h) == LIB3270_CONNECTING) + { + // Connecting, disconnect + debug("%s: Stopping while connecting",__FUNCTION__); + lib3270_disconnect(h); + + } + + // Do we have pending tasks? + if(h->tasks) + { + lib3270_write_log(h,LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),"Destroying session with %u active task(s)",h->tasks); + } shutdown_toggles(h); diff --git a/src/include/internals.h b/src/include/internals.h index e484505..9e76ad7 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -674,6 +674,7 @@ struct _h3270 } listeners; + unsigned int tasks; }; diff --git a/src/include/lib3270/properties.h b/src/include/lib3270/properties.h index 222d940..9cb570f 100644 --- a/src/include/lib3270/properties.h +++ b/src/include/lib3270/properties.h @@ -275,6 +275,16 @@ */ LIB3270_EXPORT const char * lib3270_service_get_name(const H3270 *h); + /** + * @brief Check if there's an active task. + * + * @param h Session handle. + * + * @return Number of background tasks. + * + */ + LIB3270_EXPORT unsigned int lib3270_get_task_count(const H3270 *h); + #ifdef __cplusplus } #endif -- libgit2 0.21.2