diff options
-rw-r--r-- | doc/man/gnunet-search.1 | 4 | ||||
-rw-r--r-- | src/fs/gnunet-search.c | 23 | ||||
-rw-r--r-- | src/include/gnunet_getopt_lib.h | 18 | ||||
-rw-r--r-- | src/util/getopt_helpers.c | 32 |
4 files changed, 61 insertions, 16 deletions
diff --git a/doc/man/gnunet-search.1 b/doc/man/gnunet-search.1 index 3607c81d5..05ab27562 100644 --- a/doc/man/gnunet-search.1 +++ b/doc/man/gnunet-search.1 | |||
@@ -47,8 +47,8 @@ Only search locally, do not forward requests to other peers. | |||
47 | automatically terminate the search after receiving VALUE results. | 47 | automatically terminate the search after receiving VALUE results. |
48 | 48 | ||
49 | .TP | 49 | .TP |
50 | \fB\-t \fIVALUE\fR, \fB\-\-timeout=\fIVALUE\fR | 50 | \fB\-t \fIDELAY\fR, \fB\-\-timeout=\fIDELAY\fR |
51 | Automatically timeout search after VALUE ms. Otherwise the search runs until gnunet\-search is aborted with CTRL\-C. | 51 | Automatically timeout search after DELAY. The value given must be a number followed by a space and a time unit, for example "500 ms". Note that the quotes are required on the shell. Otherwise the search runs until gnunet\-search is aborted with CTRL\-C. |
52 | 52 | ||
53 | .TP | 53 | .TP |
54 | \fB\-v\fR, \fB\-\-version\fR | 54 | \fB\-v\fR, \fB\-\-version\fR |
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index 88507f608..200dc77ab 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c | |||
@@ -42,11 +42,14 @@ static struct GNUNET_FS_DirectoryBuilder *db; | |||
42 | 42 | ||
43 | static unsigned int anonymity = 1; | 43 | static unsigned int anonymity = 1; |
44 | 44 | ||
45 | static unsigned long long timeout; | 45 | /** |
46 | * Timeout for the search, 0 means to wait for CTRL-C. | ||
47 | */ | ||
48 | static struct GNUNET_TIME_Relative timeout; | ||
46 | 49 | ||
47 | static unsigned int results_limit; | 50 | static unsigned int results_limit; |
48 | 51 | ||
49 | static unsigned int results = 0; | 52 | static unsigned int results; |
50 | 53 | ||
51 | static int verbose; | 54 | static int verbose; |
52 | 55 | ||
@@ -220,7 +223,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
220 | struct GNUNET_FS_Uri *uri; | 223 | struct GNUNET_FS_Uri *uri; |
221 | unsigned int argc; | 224 | unsigned int argc; |
222 | enum GNUNET_FS_SearchOptions options; | 225 | enum GNUNET_FS_SearchOptions options; |
223 | struct GNUNET_TIME_Relative delay; | ||
224 | 226 | ||
225 | argc = 0; | 227 | argc = 0; |
226 | while (NULL != args[argc]) | 228 | while (NULL != args[argc]) |
@@ -257,16 +259,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
257 | ret = 1; | 259 | ret = 1; |
258 | return; | 260 | return; |
259 | } | 261 | } |
260 | if (timeout != 0) | 262 | if (0 != timeout.rel_value) |
261 | { | 263 | GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL); |
262 | delay.rel_value = timeout; | ||
263 | GNUNET_SCHEDULER_add_delayed (delay, &shutdown_task, NULL); | ||
264 | } | ||
265 | else | 264 | else |
266 | { | ||
267 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 265 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
268 | NULL); | 266 | NULL); |
269 | } | ||
270 | } | 267 | } |
271 | 268 | ||
272 | 269 | ||
@@ -290,9 +287,9 @@ main (int argc, char *const *argv) | |||
290 | {'o', "output", "PREFIX", | 287 | {'o', "output", "PREFIX", |
291 | gettext_noop ("write search results to file starting with PREFIX"), | 288 | gettext_noop ("write search results to file starting with PREFIX"), |
292 | 1, &GNUNET_GETOPT_set_string, &output_filename}, | 289 | 1, &GNUNET_GETOPT_set_string, &output_filename}, |
293 | {'t', "timeout", "VALUE", | 290 | {'t', "timeout", "DELAY", |
294 | gettext_noop ("automatically terminate search after VALUE ms"), | 291 | gettext_noop ("automatically terminate search after DELAY"), |
295 | 1, &GNUNET_GETOPT_set_ulong, &timeout}, | 292 | 1, &GNUNET_GETOPT_set_relative_time, &timeout}, |
296 | {'V', "verbose", NULL, | 293 | {'V', "verbose", NULL, |
297 | gettext_noop ("be verbose (print progress information)"), | 294 | gettext_noop ("be verbose (print progress information)"), |
298 | 0, &GNUNET_GETOPT_set_one, &verbose}, | 295 | 0, &GNUNET_GETOPT_set_one, &verbose}, |
diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h index 4b1873c6e..14ba15d66 100644 --- a/src/include/gnunet_getopt_lib.h +++ b/src/include/gnunet_getopt_lib.h | |||
@@ -232,6 +232,24 @@ GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
232 | 232 | ||
233 | 233 | ||
234 | /** | 234 | /** |
235 | * Set an option of type 'struct GNUNET_TIME_Relative' from the command line. | ||
236 | * A pointer to this function should be passed as part of the | ||
237 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options | ||
238 | * of this type. It should be followed by a pointer to a value of | ||
239 | * type 'struct GNUNET_TIME_Relative'. | ||
240 | * | ||
241 | * @param ctx command line processing context | ||
242 | * @param scls additional closure (will point to the 'struct GNUNET_TIME_Relative') | ||
243 | * @param option name of the option | ||
244 | * @param value actual value of the option as a string. | ||
245 | * @return GNUNET_OK if parsing the value worked | ||
246 | */ | ||
247 | int | ||
248 | GNUNET_GETOPT_set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | ||
249 | void *scls, const char *option, const char *value); | ||
250 | |||
251 | |||
252 | /** | ||
235 | * Set an option of type 'unsigned int' from the command line. | 253 | * Set an option of type 'unsigned int' from the command line. |
236 | * A pointer to this function should be passed as part of the | 254 | * A pointer to this function should be passed as part of the |
237 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options | 255 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options |
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c index a31080fa0..a80bff4a3 100644 --- a/src/util/getopt_helpers.c +++ b/src/util/getopt_helpers.c | |||
@@ -26,7 +26,7 @@ | |||
26 | 26 | ||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_common.h" | 28 | #include "gnunet_common.h" |
29 | #include "gnunet_getopt_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | 31 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) |
32 | 32 | ||
@@ -263,6 +263,36 @@ GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
263 | 263 | ||
264 | 264 | ||
265 | /** | 265 | /** |
266 | * Set an option of type 'struct GNUNET_TIME_Relative' from the command line. | ||
267 | * A pointer to this function should be passed as part of the | ||
268 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options | ||
269 | * of this type. It should be followed by a pointer to a value of | ||
270 | * type 'struct GNUNET_TIME_Relative'. | ||
271 | * | ||
272 | * @param ctx command line processing context | ||
273 | * @param scls additional closure (will point to the 'struct GNUNET_TIME_Relative') | ||
274 | * @param option name of the option | ||
275 | * @param value actual value of the option as a string. | ||
276 | * @return GNUNET_OK if parsing the value worked | ||
277 | */ | ||
278 | int | ||
279 | GNUNET_GETOPT_set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | ||
280 | void *scls, const char *option, const char *value) | ||
281 | { | ||
282 | struct GNUNET_TIME_Relative *val = scls; | ||
283 | |||
284 | if (GNUNET_OK != | ||
285 | GNUNET_STRINGS_fancy_time_to_relative (value, | ||
286 | val)) | ||
287 | { | ||
288 | FPRINTF (stderr, _("You must pass relative time to the `%s' option.\n"), option); | ||
289 | return GNUNET_SYSERR; | ||
290 | } | ||
291 | return GNUNET_OK; | ||
292 | } | ||
293 | |||
294 | |||
295 | /** | ||
266 | * Set an option of type 'unsigned int' from the command line. | 296 | * Set an option of type 'unsigned int' from the command line. |
267 | * A pointer to this function should be passed as part of the | 297 | * A pointer to this function should be passed as part of the |
268 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options | 298 | * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options |