ats_ril: - removed some redundantly saved plugin environment attributes
[oweals/gnunet.git] / src / fs / test_fs_search.c
index cf4a9cb41e2b35ff9771ab7afb2832c89e1ae4ff..faf8727a6b071d57d570faa846a2cf7dd63bfb11 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2004, 2005, 2006, 2008, 2009 Christian Grothoff (and other contributing authors)
+     (C) 2004-2013 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -52,21 +52,55 @@ static struct GNUNET_FS_SearchContext *search;
 
 static struct GNUNET_FS_PublishContext *publish;
 
+static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+
+static int err;
+
 
 static void
 abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{                                      
+  if (NULL != publish)
+  {
+    GNUNET_FS_publish_stop (publish);
+    publish = NULL;
+  }
+  if (GNUNET_SCHEDULER_NO_TASK != timeout_task)
+  {
+    GNUNET_SCHEDULER_cancel (timeout_task);
+    timeout_task = GNUNET_SCHEDULER_NO_TASK;
+  }
+}
+
+
+static void
+abort_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_FS_publish_stop (publish);
-  publish = NULL;
+  fprintf (stderr,
+          "Timeout\n");
+  timeout_task = GNUNET_SCHEDULER_NO_TASK;
+  if (NULL != search)
+  {
+    GNUNET_FS_search_stop (search);
+    search = NULL;
+  }
+  if (NULL != publish)
+  {
+    GNUNET_FS_publish_stop (publish);
+    publish = NULL;
+  }
+  err = 1;
 }
 
 
 static void
 abort_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  if (search != NULL)
+  if (NULL != search)
+  {
     GNUNET_FS_search_stop (search);
-  search = NULL;
+    search = NULL;
+  }
 }
 
 
@@ -190,6 +224,8 @@ run (void *cls,
       GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
                                GNUNET_FS_PUBLISH_OPTION_NONE);
   GNUNET_assert (publish != NULL);
+  timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME,
+                                              &abort_error, NULL);
 }
 
 
@@ -200,7 +236,7 @@ main (int argc, char *argv[])
                                    "test_fs_search_data.conf",
                                    &run, NULL))
     return 1;
-  return 0;
+  return err;
 }
 
 /* end of test_fs_search.c */