From ba2a2d286a0ca4e75e6ca24abea6bdf5b383d26c Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 20 Feb 2018 14:40:25 -0300 Subject: [PATCH] Melhorando tratamento de timeouts durante a transferência de arquivos. --- src/pw3270/v3270ft/private.h | 1 + src/pw3270/v3270ft/v3270ftprogress.c | 44 +++++++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/pw3270/v3270ft/private.h b/src/pw3270/v3270ft/private.h index c32c9ca..7307dc4 100644 --- a/src/pw3270/v3270ft/private.h +++ b/src/pw3270/v3270ft/private.h @@ -143,6 +143,7 @@ struct v3270ft_entry * active; ///< Transferência em andamento. H3270 * session; ///< lib3270 session handle. + unsigned long current; ///< Quantidade de bytes recebidos/enviados. time_t timeout; ///< When the transfer will fail with timeout. GtkEntry * info[PROGRESS_FIELD_COUNT]; ///< Widgets com informações da transferência atual. diff --git a/src/pw3270/v3270ft/v3270ftprogress.c b/src/pw3270/v3270ft/v3270ftprogress.c index 7695d0a..7351202 100644 --- a/src/pw3270/v3270ft/v3270ftprogress.c +++ b/src/pw3270/v3270ft/v3270ftprogress.c @@ -497,10 +497,17 @@ void v3270ftprogress_update(GtkWidget *widget, unsigned long current, unsigned l gchar * text; v3270ftprogress * dialog = GTK_V3270FTPROGRESS(widget); + debug("%s(current=%lu total=%lu kbytes/sec=%u)",__FUNCTION__,current,total,(unsigned int) kbytes_sec); + if(current) { - // Tem dados, atualiza - dialog->timeout = time(NULL) + 10; + if(current != dialog->current) { + + // Recebi um bloco de dados, cancelo timeout por 10 segundos. + dialog->timeout = time(NULL) + 10; + dialog->current = current; + + } if(total) { @@ -528,27 +535,34 @@ void v3270ftprogress_update(GtkWidget *widget, unsigned long current, unsigned l gtk_progress_bar_set_fraction(dialog->progress, ((gdouble) current) / ((gdouble) total)); - } + text = g_strdup_printf("%lu",total); + gtk_entry_set_text(dialog->info[PROGRESS_FIELD_TOTAL],text); + g_free(text); - } + } else { - debug("%s(current=%lu total=%lu kbytes/sec=%u)",__FUNCTION__,current,total,(unsigned int) kbytes_sec); + gtk_entry_set_text(dialog->info[PROGRESS_FIELD_TOTAL],_("N/A")); - text = g_strdup_printf("%lu",current); - gtk_entry_set_text(dialog->info[PROGRESS_FIELD_CURRENT],text); - g_free(text); + } - if(total) { - text = g_strdup_printf("%lu",total); - gtk_entry_set_text(dialog->info[PROGRESS_FIELD_TOTAL],text); + text = g_strdup_printf("%lu",current); + gtk_entry_set_text(dialog->info[PROGRESS_FIELD_CURRENT],text); g_free(text); + } else { - gtk_entry_set_text(dialog->info[PROGRESS_FIELD_TOTAL],_("N/A")); + + // Não tem posição de arquivo + gtk_entry_set_text(dialog->info[PROGRESS_FIELD_CURRENT],_("N/A")); + } - text = g_strdup_printf("%ld KB/s",(unsigned long) kbytes_sec); - gtk_entry_set_text(dialog->info[PROGRESS_FIELD_SPEED],text); - g_free(text); + if(kbytes_sec > 0) { + text = g_strdup_printf("%ld KB/s",(unsigned long) kbytes_sec); + gtk_entry_set_text(dialog->info[PROGRESS_FIELD_SPEED],text); + g_free(text); + } else { + gtk_entry_set_text(dialog->info[PROGRESS_FIELD_SPEED],""); + } } -- libgit2 0.21.2