aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_list_indexed.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-18 19:03:26 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-18 19:03:26 +0000
commitc456c5bb7f9b95d1800ad6e2892a77f40a08493e (patch)
tree8b04e75f8a65225848816d8e588b28413ff9d758 /src/fs/fs_list_indexed.c
parent6d0a62078edfa5c0001acb93d517c674c5124f4e (diff)
downloadgnunet-c456c5bb7f9b95d1800ad6e2892a77f40a08493e.tar.gz
gnunet-c456c5bb7f9b95d1800ad6e2892a77f40a08493e.zip
make all (?) asynchronously operating FS operations actually cancel-able
Diffstat (limited to 'src/fs/fs_list_indexed.c')
-rw-r--r--src/fs/fs_list_indexed.c65
1 files changed, 31 insertions, 34 deletions
diff --git a/src/fs/fs_list_indexed.c b/src/fs/fs_list_indexed.c
index 0896de347..784c9881a 100644
--- a/src/fs/fs_list_indexed.c
+++ b/src/fs/fs_list_indexed.c
@@ -34,7 +34,7 @@
34/** 34/**
35 * Context for "GNUNET_FS_get_indexed_files". 35 * Context for "GNUNET_FS_get_indexed_files".
36 */ 36 */
37struct GetIndexedContext 37struct GNUNET_FS_GetIndexedContext
38{ 38{
39 /** 39 /**
40 * Handle to global FS context. 40 * Handle to global FS context.
@@ -72,13 +72,13 @@ struct GetIndexedContext
72 * Function called on each response from the FS 72 * Function called on each response from the FS
73 * service with information about indexed files. 73 * service with information about indexed files.
74 * 74 *
75 * @param cls closure (of type "struct GetIndexedContext*") 75 * @param cls closure (of type "struct GNUNET_FS_GetIndexedContext*")
76 * @param msg message with indexing information 76 * @param msg message with indexing information
77 */ 77 */
78static void 78static void
79handle_index_info (void *cls, const struct GNUNET_MessageHeader *msg) 79handle_index_info (void *cls, const struct GNUNET_MessageHeader *msg)
80{ 80{
81 struct GetIndexedContext *gic = cls; 81 struct GNUNET_FS_GetIndexedContext *gic = cls;
82 const struct IndexInfoMessage *iim; 82 const struct IndexInfoMessage *iim;
83 uint16_t msize; 83 uint16_t msize;
84 const char *filename; 84 const char *filename;
@@ -89,19 +89,15 @@ handle_index_info (void *cls, const struct GNUNET_MessageHeader *msg)
89 _ 89 _
90 ("Failed to receive response for `%s' request from `%s' service.\n"), 90 ("Failed to receive response for `%s' request from `%s' service.\n"),
91 "GET_INDEXED", "fs"); 91 "GET_INDEXED", "fs");
92 GNUNET_SCHEDULER_add_continuation (gic->cont, gic->cont_cls, 92 (void) gic->iterator (gic->iterator_cls, NULL, NULL);
93 GNUNET_SCHEDULER_REASON_TIMEOUT); 93 GNUNET_FS_get_indexed_files_cancel (gic);
94 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
95 GNUNET_free (gic);
96 return; 94 return;
97 } 95 }
98 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END) 96 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END)
99 { 97 {
100 /* normal end-of-list */ 98 /* normal end-of-list */
101 GNUNET_SCHEDULER_add_continuation (gic->cont, gic->cont_cls, 99 (void) gic->iterator (gic->iterator_cls, NULL, NULL);
102 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 100 GNUNET_FS_get_indexed_files_cancel (gic);
103 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
104 GNUNET_free (gic);
105 return; 101 return;
106 } 102 }
107 msize = ntohs (msg->size); 103 msize = ntohs (msg->size);
@@ -116,18 +112,13 @@ handle_index_info (void *cls, const struct GNUNET_MessageHeader *msg)
116 _ 112 _
117 ("Failed to receive valid response for `%s' request from `%s' service.\n"), 113 ("Failed to receive valid response for `%s' request from `%s' service.\n"),
118 "GET_INDEXED", "fs"); 114 "GET_INDEXED", "fs");
119 GNUNET_SCHEDULER_add_continuation (gic->cont, gic->cont_cls, 115 (void) gic->iterator (gic->iterator_cls, NULL, NULL);
120 GNUNET_SCHEDULER_REASON_TIMEOUT); 116 GNUNET_FS_get_indexed_files_cancel (gic);
121 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
122 GNUNET_free (gic);
123 return; 117 return;
124 } 118 }
125 if (GNUNET_OK != gic->iterator (gic->iterator_cls, filename, &iim->file_id)) 119 if (GNUNET_OK != gic->iterator (gic->iterator_cls, filename, &iim->file_id))
126 { 120 {
127 GNUNET_SCHEDULER_add_continuation (gic->cont, gic->cont_cls, 121 GNUNET_FS_get_indexed_files_cancel (gic);
128 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
129 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
130 GNUNET_free (gic);
131 return; 122 return;
132 } 123 }
133 /* get more */ 124 /* get more */
@@ -142,19 +133,15 @@ handle_index_info (void *cls, const struct GNUNET_MessageHeader *msg)
142 * @param h handle to the file sharing subsystem 133 * @param h handle to the file sharing subsystem
143 * @param iterator function to call on each indexed file 134 * @param iterator function to call on each indexed file
144 * @param iterator_cls closure for iterator 135 * @param iterator_cls closure for iterator
145 * @param cont continuation to call when done; 136 * @return NULL on error ('iter' is not called)
146 * reason should be "TIMEOUT" (on
147 * error) or "PREREQ_DONE" (on success)
148 * @param cont_cls closure for cont
149 */ 137 */
150void 138struct GNUNET_FS_GetIndexedContext *
151GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, 139GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
152 GNUNET_FS_IndexedFileProcessor iterator, 140 GNUNET_FS_IndexedFileProcessor iterator,
153 void *iterator_cls, GNUNET_SCHEDULER_Task cont, 141 void *iterator_cls)
154 void *cont_cls)
155{ 142{
156 struct GNUNET_CLIENT_Connection *client; 143 struct GNUNET_CLIENT_Connection *client;
157 struct GetIndexedContext *gic; 144 struct GNUNET_FS_GetIndexedContext *gic;
158 struct GNUNET_MessageHeader msg; 145 struct GNUNET_MessageHeader msg;
159 146
160 client = GNUNET_CLIENT_connect ("fs", h->cfg); 147 client = GNUNET_CLIENT_connect ("fs", h->cfg);
@@ -162,18 +149,13 @@ GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
162 { 149 {
163 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 150 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
164 _("Failed to not connect to `%s' service.\n"), "fs"); 151 _("Failed to not connect to `%s' service.\n"), "fs");
165 GNUNET_SCHEDULER_add_continuation (cont, cont_cls, 152 return NULL;
166 GNUNET_SCHEDULER_REASON_TIMEOUT);
167 return;
168 } 153 }
169 154 gic = GNUNET_malloc (sizeof (struct GNUNET_FS_GetIndexedContext));
170 gic = GNUNET_malloc (sizeof (struct GetIndexedContext));
171 gic->h = h; 155 gic->h = h;
172 gic->client = client; 156 gic->client = client;
173 gic->iterator = iterator; 157 gic->iterator = iterator;
174 gic->iterator_cls = iterator_cls; 158 gic->iterator_cls = iterator_cls;
175 gic->cont = cont;
176 gic->cont_cls = cont_cls;
177 msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 159 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
178 msg.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET); 160 msg.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET);
179 GNUNET_assert (GNUNET_OK == 161 GNUNET_assert (GNUNET_OK ==
@@ -182,6 +164,21 @@ GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
182 GNUNET_YES, 164 GNUNET_YES,
183 &handle_index_info, 165 &handle_index_info,
184 gic)); 166 gic));
167 return gic;
168}
169
170
171/**
172 * Cancel iteration over all indexed files.
173 *
174 * @param gic operation to cancel
175 */
176void
177GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic)
178{
179 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
180 GNUNET_free (gic);
185} 181}
186 182
183
187/* end of fs_list_indexed.c */ 184/* end of fs_list_indexed.c */