Commit f26c27d8338d89af61fc9877773e9926e9fa0b05

Authored by Perry Werneck
1 parent 8ce1e522
Exists in master and in 2 other branches develop, macos

Adding background task counter.

src/core/iocalls.c
@@ -465,9 +465,10 @@ LIB3270_EXPORT int lib3270_run_task(H3270 *hSession, int(*callback)(H3270 *h, vo @@ -465,9 +465,10 @@ LIB3270_EXPORT int lib3270_run_task(H3270 *hSession, int(*callback)(H3270 *h, vo
465 CHECK_SESSION_HANDLE(hSession); 465 CHECK_SESSION_HANDLE(hSession);
466 466
467 hSession->cbk.set_timer(hSession,1); 467 hSession->cbk.set_timer(hSession,1);
  468 + hSession->tasks++;
468 rc = run_task(hSession,callback,parm); 469 rc = run_task(hSession,callback,parm);
469 hSession->cbk.set_timer(hSession,0); 470 hSession->cbk.set_timer(hSession,0);
470 - 471 + hSession->tasks--;
471 return rc; 472 return rc;
472 473
473 } 474 }
src/core/properties/unsigned.c
@@ -198,3 +198,8 @@ int lib3270_set_uint_property(H3270 *hSession, const char *name, unsigned int va @@ -198,3 +198,8 @@ int lib3270_set_uint_property(H3270 *hSession, const char *name, unsigned int va
198 198
199 } 199 }
200 200
  201 +LIB3270_EXPORT unsigned int lib3270_get_task_count(const H3270 *h)
  202 +{
  203 + return h->tasks;
  204 +}
  205 +
src/core/session.c
@@ -67,9 +67,24 @@ void lib3270_session_free(H3270 *h) @@ -67,9 +67,24 @@ void lib3270_session_free(H3270 *h)
67 if(!h) 67 if(!h)
68 return; 68 return;
69 69
70 - // Terminate session  
71 if(lib3270_is_connected(h)) 70 if(lib3270_is_connected(h))
  71 + {
  72 + // Connected, disconnect
72 lib3270_disconnect(h); 73 lib3270_disconnect(h);
  74 + }
  75 + else if(lib3270_get_connection_state(h) == LIB3270_CONNECTING)
  76 + {
  77 + // Connecting, disconnect
  78 + debug("%s: Stopping while connecting",__FUNCTION__);
  79 + lib3270_disconnect(h);
  80 +
  81 + }
  82 +
  83 + // Do we have pending tasks?
  84 + if(h->tasks)
  85 + {
  86 + lib3270_write_log(h,LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),"Destroying session with %u active task(s)",h->tasks);
  87 + }
73 88
74 shutdown_toggles(h); 89 shutdown_toggles(h);
75 90
src/include/internals.h
@@ -674,6 +674,7 @@ struct _h3270 @@ -674,6 +674,7 @@ struct _h3270
674 674
675 } listeners; 675 } listeners;
676 676
  677 + unsigned int tasks;
677 678
678 }; 679 };
679 680
src/include/lib3270/properties.h
@@ -275,6 +275,16 @@ @@ -275,6 +275,16 @@
275 */ 275 */
276 LIB3270_EXPORT const char * lib3270_service_get_name(const H3270 *h); 276 LIB3270_EXPORT const char * lib3270_service_get_name(const H3270 *h);
277 277
  278 + /**
  279 + * @brief Check if there's an active task.
  280 + *
  281 + * @param h Session handle.
  282 + *
  283 + * @return Number of background tasks.
  284 + *
  285 + */
  286 + LIB3270_EXPORT unsigned int lib3270_get_task_count(const H3270 *h);
  287 +
278 #ifdef __cplusplus 288 #ifdef __cplusplus
279 } 289 }
280 #endif 290 #endif