changeset 873:42f9ce5e4bff

2007-2-4 Brian Masney <masneyb@gftp.org> * src/uicommon/gftpui.c - don't use a sigjmp buffer for the stop button. Instead, make sure a signal is delivered to the child thread and the thread will exit gracefully. Removed unused functions: _gftpui_cb_connect() and _gftpui_cb_disconnect() * src/gtk/gftp-gtk.c (stop_button) - set the cancel variable inside the gftp_request structure when the stop button is pressed.
author masneyb
date Sun, 04 Feb 2007 21:29:38 +0000
parents d7cbef177dfc
children a15adc70e327
files ChangeLog src/gtk/gftp-gtk.c src/uicommon/gftpui.c
diffstat 3 files changed, 42 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Feb 04 21:25:46 2007 +0000
+++ b/ChangeLog	Sun Feb 04 21:29:38 2007 +0000
@@ -1,4 +1,12 @@
 2007-2-4 Brian Masney <masneyb@gftp.org>
+	* src/uicommon/gftpui.c - don't use a sigjmp buffer for the stop
+	button. Instead, make sure a signal is delivered to the child thread
+	and the thread will exit gracefully. Removed unused functions:
+	_gftpui_cb_connect() and _gftpui_cb_disconnect()
+
+	* src/gtk/gftp-gtk.c (stop_button) - set the cancel variable inside
+	the gftp_request structure when the stop button is pressed.
+
 	* lib/sshv2.c (sshv2_start_login_sequence) - when checking for
 	EINTR/EGAIN, only stop trying to connect if the current operation
 	was to be cancelled.
--- a/src/gtk/gftp-gtk.c	Sun Feb 04 21:25:46 2007 +0000
+++ b/src/gtk/gftp-gtk.c	Sun Feb 04 21:29:38 2007 +0000
@@ -1251,9 +1251,15 @@
 
   memset (&comptid, 0, sizeof (comptid));
   if (!pthread_equal (comptid, window1.tid))
-    pthread_kill (window1.tid, SIGINT);
+    {
+      window1.request->cancel = 1;
+      pthread_kill (window1.tid, SIGINT);
+    }
   else if (!pthread_equal (comptid, window2.tid))
-    pthread_kill (window2.tid, SIGINT);
+    {
+      window2.request->cancel = 1;
+      pthread_kill (window2.tid, SIGINT);
+    }
 }
 
 
--- a/src/uicommon/gftpui.c	Sun Feb 04 21:25:46 2007 +0000
+++ b/src/uicommon/gftpui.c	Sun Feb 04 21:29:38 2007 +0000
@@ -20,84 +20,58 @@
 #include "gftpui.h"
 static const char cvsid[] = "$Id$";
 
-sigjmp_buf gftpui_common_jmp_environment;
-volatile int gftpui_common_use_jmp_environment = 0;
-
 GStaticMutex gftpui_common_transfer_mutex = G_STATIC_MUTEX_INIT;
 volatile sig_atomic_t gftpui_common_child_process_done = 0;
+volatile sig_atomic_t gftpui_common_num_child_threads = 0;
 static gftp_logging_func gftpui_common_logfunc;
 
-
-static int
-_gftpui_cb_connect (gftpui_callback_data * cdata)
-{
-  if (cdata->connect_function != NULL)
-    return (cdata->connect_function (cdata));
-  else
-    return (gftp_connect (cdata->request));
-}
-
-
-static void
-_gftpui_cb_disconnect (gftpui_callback_data * cdata)
-{
-  if (cdata->connect_function != NULL)
-    cdata->disconnect_function (cdata);
-  else
-    gftp_disconnect (cdata->request);
-}
-
-
 static void *
 _gftpui_common_thread_callback (void * data)
 { 
   intptr_t network_timeout, sleep_time;
   gftpui_callback_data * cdata;
   struct timespec ts;
-  int success, sj;
+  int success;
 
   cdata = data;
+  gftpui_common_num_child_threads++;
+
   gftp_lookup_request_option (cdata->request, "network_timeout",
                               &network_timeout);
   gftp_lookup_request_option (cdata->request, "sleep_time",
                               &sleep_time);
 
-  sj = sigsetjmp (gftpui_common_jmp_environment, 1);
-  gftpui_common_use_jmp_environment = 1;
-
   success = GFTP_ERETRYABLE;
-  if (sj != 1)
+  while (1)
     {
-      while (1)
-        {
-          if (network_timeout > 0)
-            alarm (network_timeout);
-          success = cdata->run_function (cdata);
-          alarm (0);
+      if (network_timeout > 0)
+        alarm (network_timeout);
 
-          if (success == GFTP_EFATAL || success == 0 || cdata->retries == 0)
-            break;
+      success = cdata->run_function (cdata);
+      alarm (0);
 
-          cdata->retries--;
+      if (cdata->request->cancel)
+        {
           cdata->request->logging_function (gftp_logging_error, cdata->request,
-                       _("Waiting %d seconds until trying to connect again\n"),
-                       sleep_time);
+                                            _("Operation canceled\n"));
+          break;
+        }
+        
+      if (success == GFTP_EFATAL || success == 0 || cdata->retries == 0)
+        break;
 
-	  ts.tv_sec = sleep_time;
-	  ts.tv_nsec = 0;
-	  if (nanosleep (&ts, NULL) == 0)
-            siglongjmp (gftpui_common_jmp_environment, 2);
-        }
-    }
-  else
-    {
-      _gftpui_cb_disconnect (cdata);
+      cdata->retries--;
       cdata->request->logging_function (gftp_logging_error, cdata->request,
-                                        _("Operation canceled\n"));
+                   _("Waiting %d seconds until trying to connect again\n"),
+                   sleep_time);
+
+      ts.tv_sec = sleep_time;
+      ts.tv_nsec = 0;
+      nanosleep (&ts, NULL);
     }
 
-  gftpui_common_use_jmp_environment = 0;
   cdata->request->stopable = 0;
+  gftpui_common_num_child_threads--;
 
   return (GINT_TO_POINTER (success));
 }
@@ -128,9 +102,7 @@
 {
   signal (signo, gftpui_common_signal_handler);
 
-  if (gftpui_common_use_jmp_environment)
-    siglongjmp (gftpui_common_jmp_environment, signo == SIGINT ? 1 : 2);
-  else if (signo == SIGINT)
+  if (!gftpui_common_num_child_threads && signo == SIGINT)
     exit (EXIT_FAILURE);
 }