# HG changeset patch # User masneyb # Date 1170816237 0 # Node ID 2d4e6fca8e7cd42567839c26c76fa28b87d71a1b # Parent 19dacfb6943324bc15dca29902ff3c436c793bc9 2007-2-6 Brian Masney * src/text/textui.c src/gtk/gtkui_transfer.c src/uicommon/gftpui.h - added new function: gftpui_cancel_file_transfer() * src/uicommon/gftpui.c - use gftpui_cancel_file_transfer() to cancel the file transfers * lib/gftp.h lib/misc.c src/gtk/transfer.c - added pointer for the thread_id of the transfer to the gftp_transfer structure. This will be used in the GTK+ port so that the transfer can be stopped. diff -r 19dacfb69433 -r 2d4e6fca8e7c ChangeLog --- a/ChangeLog Wed Feb 07 01:56:20 2007 +0000 +++ b/ChangeLog Wed Feb 07 02:43:57 2007 +0000 @@ -1,4 +1,14 @@ 2007-2-6 Brian Masney + * src/text/textui.c src/gtk/gtkui_transfer.c src/uicommon/gftpui.h - + added new function: gftpui_cancel_file_transfer() + + * src/uicommon/gftpui.c - use gftpui_cancel_file_transfer() to cancel + the file transfers + + * lib/gftp.h lib/misc.c src/gtk/transfer.c - added pointer for the + thread_id of the transfer to the gftp_transfer structure. This will be + used in the GTK+ port so that the transfer can be stopped. + * src/gtk/menu-items.c - removed duplicated code that was found by PMD 2007-2-5 Brian Masney diff -r 19dacfb69433 -r 2d4e6fca8e7c lib/gftp.h --- a/lib/gftp.h Wed Feb 07 01:56:20 2007 +0000 +++ b/lib/gftp.h Wed Feb 07 02:43:57 2007 +0000 @@ -557,6 +557,7 @@ structmutex; void *user_data; + void *thread_id; void *clist; } gftp_transfer; diff -r 19dacfb69433 -r 2d4e6fca8e7c lib/misc.c --- a/lib/misc.c Wed Feb 07 01:56:20 2007 +0000 +++ b/lib/misc.c Wed Feb 07 02:43:57 2007 +0000 @@ -561,6 +561,8 @@ if (tdata->toreq != NULL) gftp_request_destroy (tdata->toreq, 1); free_file_list (tdata->files); + if (tdata->thread_id != NULL) + g_free (tdata->thread_id); g_free (tdata); } diff -r 19dacfb69433 -r 2d4e6fca8e7c src/gtk/gtkui_transfer.c --- a/src/gtk/gtkui_transfer.c Wed Feb 07 01:56:20 2007 +0000 +++ b/src/gtk/gtkui_transfer.c Wed Feb 07 02:43:57 2007 +0000 @@ -73,6 +73,18 @@ } +void +gftpui_cancel_file_transfer (gftp_transfer * tdata) +{ + if (tdata->thread_id != NULL) + pthread_kill (*(pthread_t *) tdata->thread_id, SIGINT); + + tdata->cancel = 1; /* FIXME */ + tdata->fromreq->cancel = 1; + tdata->toreq->cancel = 1; +} + + static void gftpui_gtk_trans_selectall (GtkWidget * widget, gpointer data) { diff -r 19dacfb69433 -r 2d4e6fca8e7c src/gtk/transfer.c --- a/src/gtk/transfer.c Wed Feb 07 01:56:20 2007 +0000 +++ b/src/gtk/transfer.c Wed Feb 07 02:43:57 2007 +0000 @@ -686,33 +686,35 @@ static void create_transfer (gftp_transfer * tdata) { - pthread_t tid; + if (tdata->fromreq->stopable) + return; - if (!tdata->fromreq->stopable) + if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->fromwdata, + tdata->fromreq)) { - if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->fromwdata, - tdata->fromreq)) - { - gftp_swap_socks (tdata->fromreq, - ((gftp_window_data *) tdata->fromwdata)->request); - update_window (tdata->fromwdata); - } + gftp_swap_socks (tdata->fromreq, + ((gftp_window_data *) tdata->fromwdata)->request); + update_window (tdata->fromwdata); + } - if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->towdata, - tdata->toreq)) - { - gftp_swap_socks (tdata->toreq, - ((gftp_window_data *) tdata->towdata)->request); - update_window (tdata->towdata); - } + if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->towdata, + tdata->toreq)) + { + gftp_swap_socks (tdata->toreq, + ((gftp_window_data *) tdata->towdata)->request); + update_window (tdata->towdata); + } - num_transfers_in_progress++; - tdata->started = 1; - tdata->stalled = 1; - gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, - _("Connecting...")); - pthread_create (&tid, NULL, _gftpui_transfer_files, tdata); - } + num_transfers_in_progress++; + tdata->started = 1; + tdata->stalled = 1; + gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, + _("Connecting...")); + + if (tdata->thread_id == NULL) + tdata->thread_id = g_malloc0 (sizeof (pthread_t)); + + pthread_create (tdata->thread_id, NULL, _gftpui_transfer_files, tdata); } diff -r 19dacfb69433 -r 2d4e6fca8e7c src/text/textui.c --- a/src/text/textui.c Wed Feb 07 01:56:20 2007 +0000 +++ b/src/text/textui.c Wed Feb 07 02:43:57 2007 +0000 @@ -101,6 +101,15 @@ void +gftpui_cancel_file_transfer (gftp_transfer * tdata) +{ + tdata->cancel = 1; + tdata->fromreq->cancel = 1; + tdata->toreq->cancel = 1; +} + + +void gftpui_ask_transfer (gftp_transfer * tdata) { char buf, question[1024], srcsize[50], destsize[50], *pos, defaction; diff -r 19dacfb69433 -r 2d4e6fca8e7c src/uicommon/gftpui.c --- a/src/uicommon/gftpui.c Wed Feb 07 01:56:20 2007 +0000 +++ b/src/uicommon/gftpui.c Wed Feb 07 02:43:57 2007 +0000 @@ -1348,9 +1348,7 @@ curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; if (tdata->curfle != NULL && curfle == tdata->curfle->data) { - tdata->cancel = 1; - tdata->fromreq->cancel = 1; - tdata->toreq->cancel = 1; + gftpui_cancel_file_transfer (tdata); tdata->skip_file = 1; } else if (!curfle->transfer_done) @@ -1373,9 +1371,7 @@ if (tdata->started) { - tdata->cancel = 1; - tdata->fromreq->cancel = 1; - tdata->toreq->cancel = 1; + gftpui_cancel_file_transfer (tdata); tdata->skip_file = 0; } else @@ -1552,6 +1548,8 @@ int ret, skipped_files; tdata->curfle = tdata->files; + gftpui_common_num_child_threads++; + gettimeofday (&tdata->starttime, NULL); memcpy (&tdata->lasttime, &tdata->starttime, sizeof (tdata->lasttime)); @@ -1596,6 +1594,8 @@ skipped_files); tdata->done = 1; + gftpui_common_num_child_threads--; + return (1); } diff -r 19dacfb69433 -r 2d4e6fca8e7c src/uicommon/gftpui.h --- a/src/uicommon/gftpui.h Wed Feb 07 01:56:20 2007 +0000 +++ b/src/uicommon/gftpui.h Wed Feb 07 02:43:57 2007 +0000 @@ -133,6 +133,8 @@ void *touidata, GList * files ); +void gftpui_cancel_file_transfer ( gftp_transfer * tdata ); + void gftpui_common_skip_file_transfer ( gftp_transfer * tdata, gftp_file * curfle );