diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-08-29 21:17:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-08-29 21:17:42 +0000 |
commit | 3d21cc1bc80d087ebe2be0dda53ac829b8649a84 (patch) | |
tree | d90c92f4577cb8ea76d2cc24bde562ae0c9278ed /src/fs | |
parent | ed862616e67f64a59a57b1a770f40a6634af00f0 (diff) | |
download | gnunet-3d21cc1bc80d087ebe2be0dda53ac829b8649a84.tar.gz gnunet-3d21cc1bc80d087ebe2be0dda53ac829b8649a84.zip |
finish publish shutdown code
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/fs.h | 15 | ||||
-rw-r--r-- | src/fs/fs_publish.c | 46 |
2 files changed, 51 insertions, 10 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h index 3f1ffad30..66190a42d 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h | |||
@@ -430,6 +430,21 @@ struct GNUNET_FS_PublishContext | |||
430 | GNUNET_SCHEDULER_TaskIdentifier upload_task; | 430 | GNUNET_SCHEDULER_TaskIdentifier upload_task; |
431 | 431 | ||
432 | /** | 432 | /** |
433 | * Typically GNUNET_NO. Set to GNUNET_YES if | ||
434 | * "upload_task" is GNUNET_SCHEDULER_NO_TASK | ||
435 | * and we're waiting for a response from the | ||
436 | * datastore service (in which case this | ||
437 | * struct must not be freed until we have that | ||
438 | * response). If someone tries to stop the | ||
439 | * download for good during this period, | ||
440 | * "in_network_wait" is set to GNUNET_SYSERR | ||
441 | * which will cause the struct to be destroyed | ||
442 | * right after we have the reply (or timeout) | ||
443 | * from the datastore service. | ||
444 | */ | ||
445 | int in_network_wait; | ||
446 | |||
447 | /** | ||
433 | * Current position in the file-tree for the | 448 | * Current position in the file-tree for the |
434 | * upload. | 449 | * upload. |
435 | */ | 450 | */ |
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 0cdc3811b..6a8bfc97a 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c | |||
@@ -107,6 +107,24 @@ make_publish_status (struct GNUNET_FS_ProgressInfo *pi, | |||
107 | 107 | ||
108 | 108 | ||
109 | /** | 109 | /** |
110 | * Cleanup the publish context, we're done | ||
111 | * with it. | ||
112 | * | ||
113 | * @param pc struct to clean up after | ||
114 | */ | ||
115 | static void | ||
116 | publish_cleanup (struct GNUNET_FS_PublishContext *sc) | ||
117 | { | ||
118 | GNUNET_FS_file_information_destroy (sc->fi, NULL, NULL); | ||
119 | GNUNET_FS_namespace_delete (sc->namespace, GNUNET_NO); | ||
120 | GNUNET_free_non_null (sc->nid); | ||
121 | GNUNET_free_non_null (sc->nuid); | ||
122 | GNUNET_DATASTORE_disconnect (sc->dsh, GNUNET_NO); | ||
123 | GNUNET_free (sc); | ||
124 | } | ||
125 | |||
126 | |||
127 | /** | ||
110 | * Function called by the datastore API with | 128 | * Function called by the datastore API with |
111 | * the result from the PUT request. | 129 | * the result from the PUT request. |
112 | * | 130 | * |
@@ -122,6 +140,15 @@ ds_put_cont (void *cls, | |||
122 | struct PutContCtx *pcc = cls; | 140 | struct PutContCtx *pcc = cls; |
123 | struct GNUNET_FS_ProgressInfo pi; | 141 | struct GNUNET_FS_ProgressInfo pi; |
124 | 142 | ||
143 | if (GNUNET_SYSERR == pcc->sc->in_network_wait) | ||
144 | { | ||
145 | /* we were aborted in the meantime, | ||
146 | finish shutdown! */ | ||
147 | publish_cleanup (pcc->sc); | ||
148 | return; | ||
149 | } | ||
150 | GNUNET_assert (GNUNET_YES == pcc->sc->in_network_wait); | ||
151 | pcc->sc->in_network_wait = GNUNET_NO; | ||
125 | if (GNUNET_OK != success) | 152 | if (GNUNET_OK != success) |
126 | { | 153 | { |
127 | GNUNET_asprintf (&pcc->p->emsg, | 154 | GNUNET_asprintf (&pcc->p->emsg, |
@@ -178,10 +205,8 @@ publish_block (struct GNUNET_FS_PublishContext *sc, | |||
178 | dpc_cls->cont = cont; | 205 | dpc_cls->cont = cont; |
179 | dpc_cls->sc = sc; | 206 | dpc_cls->sc = sc; |
180 | dpc_cls->p = p; | 207 | dpc_cls->p = p; |
181 | // FIXME: need to do something to "sc" to mark | 208 | GNUNET_assert (GNUNET_NO == sc->in_network_wait); |
182 | // that "sc" can not be freed right now due to this | 209 | sc->in_network_wait = GNUNET_YES; |
183 | // pending, scheduled operation for which we don't have | ||
184 | // a task ID! | ||
185 | GNUNET_DATASTORE_put (sc->dsh, | 210 | GNUNET_DATASTORE_put (sc->dsh, |
186 | sc->rid, | 211 | sc->rid, |
187 | query, | 212 | query, |
@@ -798,12 +823,13 @@ GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc) | |||
798 | GNUNET_FS_file_information_inspect (sc->fi, | 823 | GNUNET_FS_file_information_inspect (sc->fi, |
799 | &fip_signal_stop, | 824 | &fip_signal_stop, |
800 | sc); | 825 | sc); |
801 | GNUNET_FS_file_information_destroy (sc->fi, NULL, NULL); | 826 | if (GNUNET_YES == sc->in_network_wait) |
802 | GNUNET_FS_namespace_delete (sc->namespace, GNUNET_NO); | 827 | { |
803 | GNUNET_free_non_null (sc->nid); | 828 | sc->in_network_wait = GNUNET_SYSERR; |
804 | GNUNET_free_non_null (sc->nuid); | 829 | return; |
805 | GNUNET_DATASTORE_disconnect (sc->dsh, GNUNET_NO); | 830 | } |
806 | GNUNET_free (sc); | 831 | publish_cleanup (sc); |
807 | } | 832 | } |
808 | 833 | ||
834 | |||
809 | /* end of fs_publish.c */ | 835 | /* end of fs_publish.c */ |