Commit 6b500566ef311734f95288d5bd6787b8f31a0eb1

Authored by Perry Werneck
1 parent 51eeb99b
Exists in master and in 1 other branch develop

Waiting for background tasks before finalize.

Showing 2 changed files with 28 additions and 20 deletions   Show diff stats
src/terminal/iocallback.c
... ... @@ -146,12 +146,8 @@ gpointer BgCall(struct bgParameter *p)
146 146  
147 147 static int static_RunTask(H3270 *hSession, int(*callback)(H3270 *, void *), void *parm)
148 148 {
149   -// return callback(hSession,parm);
150   -
151 149 struct bgParameter p = { TRUE, hSession, -1, callback, parm };
152 150  
153   -// trace("%s starts -------------------------------------", __FUNCTION__);
154   -
155 151 p.running = TRUE;
156 152  
157 153 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
177 173  
178 174 void v3270_register_io_handlers(G_GNUC_UNUSED v3270Class *cls)
179 175 {
180   - static LIB3270_IO_CONTROLLER hdl =
  176 + static const LIB3270_IO_CONTROLLER hdl =
181 177 {
182   - sizeof(LIB3270_IO_CONTROLLER),
  178 + .sz = sizeof(LIB3270_IO_CONTROLLER),
183 179  
184   - static_AddTimer,
185   - static_RemoveTimer,
  180 + .AddTimer = static_AddTimer,
  181 + .RemoveTimer = static_RemoveTimer,
186 182  
187   - static_AddSource,
188   - static_RemoveSource,
189   - static_SetSourceState,
  183 + .add_poll = static_AddSource,
  184 + .remove_poll = static_RemoveSource,
  185 + .set_poll_state = static_SetSourceState,
190 186  
191   - static_Sleep,
192   - static_RunPendingEvents,
193   - beep,
194   - static_RunTask
  187 + .Wait = static_Sleep,
  188 + .event_dispatcher = static_RunPendingEvents,
  189 + .ring_bell = beep,
  190 + .run_task = static_RunTask
195 191  
196 192 };
197 193  
... ...
src/terminal/widget.c
... ... @@ -35,6 +35,7 @@
35 35 #include <lib3270/log.h>
36 36 #include <lib3270/toggle.h>
37 37 #include <lib3270/actions.h>
  38 + #include <lib3270/properties.h>
38 39 #include <lib3270/ssl.h>
39 40 #include <internals.h>
40 41  
... ... @@ -189,17 +190,27 @@ static void finalize(GObject *object) {
189 190  
190 191 v3270 * terminal = GTK_V3270(object);
191 192  
192   - if(terminal->remap_filename) {
193   - g_free(terminal->remap_filename);
194   - terminal->remap_filename = NULL;
195   - }
196   -
197 193 if(terminal->host) {
198 194 // Release session
  195 + debug("%s: Cleaning 3270 session",__FUNCTION__);
  196 + lib3270_disconnect(terminal->host);
  197 +
  198 + debug("Task count: %u",lib3270_get_task_count(terminal->host));
  199 + while(lib3270_get_task_count(terminal->host))
  200 + {
  201 + debug("%s: waiting",__FUNCTION__);
  202 + usleep(100);
  203 + }
  204 +
199 205 lib3270_session_free(terminal->host);
200 206 terminal->host = NULL;
201 207 }
202 208  
  209 + if(terminal->remap_filename) {
  210 + g_free(terminal->remap_filename);
  211 + terminal->remap_filename = NULL;
  212 + }
  213 +
203 214 if(terminal->accelerators) {
204 215 g_slist_free_full(terminal->accelerators,g_free);
205 216 terminal->accelerators = NULL;
... ... @@ -597,6 +608,7 @@ static void v3270_destroy(GtkWidget *widget)
597 608 // Cleanup
598 609 lib3270_reset_callbacks(terminal->host);
599 610 lib3270_set_user_data(terminal->host,NULL);
  611 + lib3270_disconnect(terminal->host);
600 612 }
601 613  
602 614 if(terminal->accessible)
... ...