diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-03-11 12:45:45 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-03-11 12:45:45 +0000 |
commit | 566fa39ac965c18fe9392ec607cbed99f0860eb9 (patch) | |
tree | 7ebf55872efc8b60eca24004eadd6f590a46a3da /src/fs/gnunet-download.c | |
parent | f6261b035e3d67813f7528bafdcc7c69f2e19300 (diff) | |
download | gnunet-566fa39ac965c18fe9392ec607cbed99f0860eb9.tar.gz gnunet-566fa39ac965c18fe9392ec607cbed99f0860eb9.zip |
fixing shutdown
Diffstat (limited to 'src/fs/gnunet-download.c')
-rw-r--r-- | src/fs/gnunet-download.c | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index 1c28cf7c9..c865a3361 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c | |||
@@ -41,12 +41,39 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
41 | 41 | ||
42 | static struct GNUNET_FS_Handle *ctx; | 42 | static struct GNUNET_FS_Handle *ctx; |
43 | 43 | ||
44 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
45 | |||
44 | static struct GNUNET_FS_DownloadContext *dc; | 46 | static struct GNUNET_FS_DownloadContext *dc; |
45 | 47 | ||
46 | static unsigned int anonymity = 1; | 48 | static unsigned int anonymity = 1; |
47 | 49 | ||
48 | static char *filename; | 50 | static char *filename; |
49 | 51 | ||
52 | |||
53 | static void | ||
54 | cleanup_task (void *cls, | ||
55 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
56 | { | ||
57 | GNUNET_FS_stop (ctx); | ||
58 | ctx = NULL; | ||
59 | } | ||
60 | |||
61 | |||
62 | static void | ||
63 | shutdown_task (void *cls, | ||
64 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
65 | { | ||
66 | struct GNUNET_FS_DownloadContext *d; | ||
67 | |||
68 | if (dc != NULL) | ||
69 | { | ||
70 | d = dc; | ||
71 | dc = NULL; | ||
72 | GNUNET_FS_download_stop (d, delete_incomplete); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | |||
50 | /** | 77 | /** |
51 | * Called by FS client to give information about the progress of an | 78 | * Called by FS client to give information about the progress of an |
52 | * operation. | 79 | * operation. |
@@ -91,7 +118,7 @@ progress_cb (void *cls, | |||
91 | fprintf (stderr, | 118 | fprintf (stderr, |
92 | _("Error downloading: %s.\n"), | 119 | _("Error downloading: %s.\n"), |
93 | info->value.download.specifics.error.message); | 120 | info->value.download.specifics.error.message); |
94 | GNUNET_FS_download_stop (dc, delete_incomplete); | 121 | GNUNET_SCHEDULER_shutdown (sched); |
95 | break; | 122 | break; |
96 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 123 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
97 | s = GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.value + 1)); | 124 | s = GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.value + 1)); |
@@ -101,11 +128,14 @@ progress_cb (void *cls, | |||
101 | s); | 128 | s); |
102 | GNUNET_free (s); | 129 | GNUNET_free (s); |
103 | if (info->value.download.dc == dc) | 130 | if (info->value.download.dc == dc) |
104 | GNUNET_FS_download_stop (dc, delete_incomplete); | 131 | GNUNET_SCHEDULER_shutdown (sched); |
105 | break; | 132 | break; |
106 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | 133 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: |
107 | if (info->value.download.dc == dc) | 134 | if (info->value.download.dc == dc) |
108 | GNUNET_FS_stop (ctx); | 135 | GNUNET_SCHEDULER_add_continuation (sched, |
136 | &cleanup_task, | ||
137 | NULL, | ||
138 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
109 | break; | 139 | break; |
110 | default: | 140 | default: |
111 | fprintf (stderr, | 141 | fprintf (stderr, |
@@ -121,14 +151,14 @@ progress_cb (void *cls, | |||
121 | * Main function that will be run by the scheduler. | 151 | * Main function that will be run by the scheduler. |
122 | * | 152 | * |
123 | * @param cls closure | 153 | * @param cls closure |
124 | * @param sched the scheduler to use | 154 | * @param s the scheduler to use |
125 | * @param args remaining command-line arguments | 155 | * @param args remaining command-line arguments |
126 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | 156 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) |
127 | * @param c configuration | 157 | * @param c configuration |
128 | */ | 158 | */ |
129 | static void | 159 | static void |
130 | run (void *cls, | 160 | run (void *cls, |
131 | struct GNUNET_SCHEDULER_Handle *sched, | 161 | struct GNUNET_SCHEDULER_Handle *s, |
132 | char *const *args, | 162 | char *const *args, |
133 | const char *cfgfile, | 163 | const char *cfgfile, |
134 | const struct GNUNET_CONFIGURATION_Handle *c) | 164 | const struct GNUNET_CONFIGURATION_Handle *c) |
@@ -137,6 +167,7 @@ run (void *cls, | |||
137 | char *emsg; | 167 | char *emsg; |
138 | enum GNUNET_FS_DownloadOptions options; | 168 | enum GNUNET_FS_DownloadOptions options; |
139 | 169 | ||
170 | sched = s; | ||
140 | /* FIXME: check arguments */ | 171 | /* FIXME: check arguments */ |
141 | uri = GNUNET_FS_uri_parse (args[0], | 172 | uri = GNUNET_FS_uri_parse (args[0], |
142 | &emsg); | 173 | &emsg); |
@@ -194,6 +225,16 @@ run (void *cls, | |||
194 | NULL, | 225 | NULL, |
195 | NULL); | 226 | NULL); |
196 | GNUNET_FS_uri_destroy (uri); | 227 | GNUNET_FS_uri_destroy (uri); |
228 | if (dc == NULL) | ||
229 | { | ||
230 | GNUNET_FS_stop (ctx); | ||
231 | ctx = NULL; | ||
232 | return; | ||
233 | } | ||
234 | GNUNET_SCHEDULER_add_delayed (sched, | ||
235 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
236 | &shutdown_task, | ||
237 | NULL); | ||
197 | } | 238 | } |
198 | 239 | ||
199 | 240 | ||