comparison src/uicommon/gftpui.c @ 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 1fae947d4418
children 2d4e6fca8e7c
comparison
equal deleted inserted replaced
872:d7cbef177dfc 873:42f9ce5e4bff
18 /*****************************************************************************/ 18 /*****************************************************************************/
19 19
20 #include "gftpui.h" 20 #include "gftpui.h"
21 static const char cvsid[] = "$Id$"; 21 static const char cvsid[] = "$Id$";
22 22
23 sigjmp_buf gftpui_common_jmp_environment;
24 volatile int gftpui_common_use_jmp_environment = 0;
25
26 GStaticMutex gftpui_common_transfer_mutex = G_STATIC_MUTEX_INIT; 23 GStaticMutex gftpui_common_transfer_mutex = G_STATIC_MUTEX_INIT;
27 volatile sig_atomic_t gftpui_common_child_process_done = 0; 24 volatile sig_atomic_t gftpui_common_child_process_done = 0;
25 volatile sig_atomic_t gftpui_common_num_child_threads = 0;
28 static gftp_logging_func gftpui_common_logfunc; 26 static gftp_logging_func gftpui_common_logfunc;
29
30
31 static int
32 _gftpui_cb_connect (gftpui_callback_data * cdata)
33 {
34 if (cdata->connect_function != NULL)
35 return (cdata->connect_function (cdata));
36 else
37 return (gftp_connect (cdata->request));
38 }
39
40
41 static void
42 _gftpui_cb_disconnect (gftpui_callback_data * cdata)
43 {
44 if (cdata->connect_function != NULL)
45 cdata->disconnect_function (cdata);
46 else
47 gftp_disconnect (cdata->request);
48 }
49
50 27
51 static void * 28 static void *
52 _gftpui_common_thread_callback (void * data) 29 _gftpui_common_thread_callback (void * data)
53 { 30 {
54 intptr_t network_timeout, sleep_time; 31 intptr_t network_timeout, sleep_time;
55 gftpui_callback_data * cdata; 32 gftpui_callback_data * cdata;
56 struct timespec ts; 33 struct timespec ts;
57 int success, sj; 34 int success;
58 35
59 cdata = data; 36 cdata = data;
37 gftpui_common_num_child_threads++;
38
60 gftp_lookup_request_option (cdata->request, "network_timeout", 39 gftp_lookup_request_option (cdata->request, "network_timeout",
61 &network_timeout); 40 &network_timeout);
62 gftp_lookup_request_option (cdata->request, "sleep_time", 41 gftp_lookup_request_option (cdata->request, "sleep_time",
63 &sleep_time); 42 &sleep_time);
64 43
65 sj = sigsetjmp (gftpui_common_jmp_environment, 1);
66 gftpui_common_use_jmp_environment = 1;
67
68 success = GFTP_ERETRYABLE; 44 success = GFTP_ERETRYABLE;
69 if (sj != 1) 45 while (1)
70 { 46 {
71 while (1) 47 if (network_timeout > 0)
72 { 48 alarm (network_timeout);
73 if (network_timeout > 0) 49
74 alarm (network_timeout); 50 success = cdata->run_function (cdata);
75 success = cdata->run_function (cdata); 51 alarm (0);
76 alarm (0); 52
77 53 if (cdata->request->cancel)
78 if (success == GFTP_EFATAL || success == 0 || cdata->retries == 0) 54 {
79 break;
80
81 cdata->retries--;
82 cdata->request->logging_function (gftp_logging_error, cdata->request, 55 cdata->request->logging_function (gftp_logging_error, cdata->request,
83 _("Waiting %d seconds until trying to connect again\n"), 56 _("Operation canceled\n"));
84 sleep_time); 57 break;
85 58 }
86 ts.tv_sec = sleep_time; 59
87 ts.tv_nsec = 0; 60 if (success == GFTP_EFATAL || success == 0 || cdata->retries == 0)
88 if (nanosleep (&ts, NULL) == 0) 61 break;
89 siglongjmp (gftpui_common_jmp_environment, 2); 62
90 } 63 cdata->retries--;
91 }
92 else
93 {
94 _gftpui_cb_disconnect (cdata);
95 cdata->request->logging_function (gftp_logging_error, cdata->request, 64 cdata->request->logging_function (gftp_logging_error, cdata->request,
96 _("Operation canceled\n")); 65 _("Waiting %d seconds until trying to connect again\n"),
97 } 66 sleep_time);
98 67
99 gftpui_common_use_jmp_environment = 0; 68 ts.tv_sec = sleep_time;
69 ts.tv_nsec = 0;
70 nanosleep (&ts, NULL);
71 }
72
100 cdata->request->stopable = 0; 73 cdata->request->stopable = 0;
74 gftpui_common_num_child_threads--;
101 75
102 return (GINT_TO_POINTER (success)); 76 return (GINT_TO_POINTER (success));
103 } 77 }
104 78
105 79
126 static RETSIGTYPE 100 static RETSIGTYPE
127 gftpui_common_signal_handler (int signo) 101 gftpui_common_signal_handler (int signo)
128 { 102 {
129 signal (signo, gftpui_common_signal_handler); 103 signal (signo, gftpui_common_signal_handler);
130 104
131 if (gftpui_common_use_jmp_environment) 105 if (!gftpui_common_num_child_threads && signo == SIGINT)
132 siglongjmp (gftpui_common_jmp_environment, signo == SIGINT ? 1 : 2);
133 else if (signo == SIGINT)
134 exit (EXIT_FAILURE); 106 exit (EXIT_FAILURE);
135 } 107 }
136 108
137 109
138 static RETSIGTYPE 110 static RETSIGTYPE