From 6b500566ef311734f95288d5bd6787b8f31a0eb1 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 16 Nov 2020 23:45:28 -0300 Subject: [PATCH] Waiting for background tasks before finalize. --- src/terminal/iocallback.c | 26 +++++++++++--------------- src/terminal/widget.c | 22 +++++++++++++++++----- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/terminal/iocallback.c b/src/terminal/iocallback.c index b0a22a9..77e9a30 100644 --- a/src/terminal/iocallback.c +++ b/src/terminal/iocallback.c @@ -146,12 +146,8 @@ gpointer BgCall(struct bgParameter *p) static int static_RunTask(H3270 *hSession, int(*callback)(H3270 *, void *), void *parm) { -// return callback(hSession,parm); - struct bgParameter p = { TRUE, hSession, -1, callback, parm }; -// trace("%s starts -------------------------------------", __FUNCTION__); - p.running = TRUE; GThread *thread = g_thread_new(PACKAGE_NAME, (GThreadFunc) BgCall, &p); @@ -177,21 +173,21 @@ static int static_RunTask(H3270 *hSession, int(*callback)(H3270 *, void *), void void v3270_register_io_handlers(G_GNUC_UNUSED v3270Class *cls) { - static LIB3270_IO_CONTROLLER hdl = + static const LIB3270_IO_CONTROLLER hdl = { - sizeof(LIB3270_IO_CONTROLLER), + .sz = sizeof(LIB3270_IO_CONTROLLER), - static_AddTimer, - static_RemoveTimer, + .AddTimer = static_AddTimer, + .RemoveTimer = static_RemoveTimer, - static_AddSource, - static_RemoveSource, - static_SetSourceState, + .add_poll = static_AddSource, + .remove_poll = static_RemoveSource, + .set_poll_state = static_SetSourceState, - static_Sleep, - static_RunPendingEvents, - beep, - static_RunTask + .Wait = static_Sleep, + .event_dispatcher = static_RunPendingEvents, + .ring_bell = beep, + .run_task = static_RunTask }; diff --git a/src/terminal/widget.c b/src/terminal/widget.c index d18a3d6..eebec1b 100644 --- a/src/terminal/widget.c +++ b/src/terminal/widget.c @@ -35,6 +35,7 @@ #include #include #include + #include #include #include @@ -189,17 +190,27 @@ static void finalize(GObject *object) { v3270 * terminal = GTK_V3270(object); - if(terminal->remap_filename) { - g_free(terminal->remap_filename); - terminal->remap_filename = NULL; - } - if(terminal->host) { // Release session + debug("%s: Cleaning 3270 session",__FUNCTION__); + lib3270_disconnect(terminal->host); + + debug("Task count: %u",lib3270_get_task_count(terminal->host)); + while(lib3270_get_task_count(terminal->host)) + { + debug("%s: waiting",__FUNCTION__); + usleep(100); + } + lib3270_session_free(terminal->host); terminal->host = NULL; } + if(terminal->remap_filename) { + g_free(terminal->remap_filename); + terminal->remap_filename = NULL; + } + if(terminal->accelerators) { g_slist_free_full(terminal->accelerators,g_free); terminal->accelerators = NULL; @@ -597,6 +608,7 @@ static void v3270_destroy(GtkWidget *widget) // Cleanup lib3270_reset_callbacks(terminal->host); lib3270_set_user_data(terminal->host,NULL); + lib3270_disconnect(terminal->host); } if(terminal->accessible) -- libgit2 0.21.2