/**
* Do we want to give our stdout to gnunet-service-arm?
*/
-static unsigned int no_stdout = 0;
+static unsigned int no_stdout;
/**
* Do we want to give our stderr to gnunet-service-arm?
*/
-static unsigned int no_stderr = 0;
+static unsigned int no_stderr;
/**
FPRINTF (stderr, "%s", _("Unknown response code from ARM.\n"));
break;
}
- GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ GNUNET_SCHEDULER_add_now (&cps_loop, NULL);
}
}
+/**
+ * Attempts to delete configuration file and SERVICEHOME
+ * on arm shutdown provided the end and delete options
+ * were specified when gnunet-arm was run.
+ */
+static void
+delete_files ()
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Will attempt to remove configuration file %s and service directory %s\n",
+ config_file, dir);
+
+ if (UNLINK (config_file) != 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to remove configuration file %s\n"), config_file);
+ }
+
+ if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to remove servicehome directory %s\n"), dir);
+
+ }
+}
+
+
+/**
+ * Main continuation-passing-style loop. Runs the various
+ * jobs that we've been asked to do in order.
+ *
+ * @param cls closure, unused
+ * @param tc context, unused
+ */
+static void
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_ARM_disconnect (h);
+ h = NULL;
+ if ((end == GNUNET_YES) && (delete == GNUNET_YES))
+ delete_files ();
+}
+
+
/**
* Main function that will be run by the scheduler.
*
ret = 1;
return;
}
- GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-}
-
-
-/**
- * Attempts to delete configuration file and SERVICEHOME
- * on arm shutdown provided the end and delete options
- * were specified when gnunet-arm was run.
- */
-static void
-delete_files ()
-{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Will attempt to remove configuration file %s and service directory %s\n",
- config_file, dir);
-
- if (UNLINK (config_file) != 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to remove configuration file %s\n"), config_file);
- }
-
- if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to remove servicehome directory %s\n"), dir);
-
- }
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_now (&cps_loop, NULL);
}
static void
cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ if (NULL == h)
+ return;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
while (1)
{
switch (phase++)
}
/* Fall through */
default: /* last phase */
- GNUNET_ARM_disconnect (h);
- if ((end == GNUNET_YES) && (delete == GNUNET_YES))
- delete_files ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
}
*/
static GNUNET_SCHEDULER_TaskIdentifier stdin_tid = GNUNET_SCHEDULER_NO_TASK;
-/**
- * Element currently being sent to the service
- */
-static struct GNUNET_CONSENSUS_Element *element;
-
-
static void
stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
}
-
static void
insert_done_cb (void *cls,
int success)
{
+ struct GNUNET_CONSENSUS_Element *element = cls;
+
+ GNUNET_free (element);
if (GNUNET_YES != success)
{
printf ("insert failed\n");
GNUNET_SCHEDULER_shutdown ();
+ return;
}
-
- GNUNET_free (element);
-
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == stdin_tid);
-
stdin_tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdin_fh,
- &stdin_cb, NULL);
+ &stdin_cb, NULL);
}
{
char buf[1024];
char *ret;
- ret = fgets (buf, 1024, stdin);
+ struct GNUNET_CONSENSUS_Element *element;
stdin_tid = GNUNET_SCHEDULER_NO_TASK;
-
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return; /* we're done here */
+ ret = fgets (buf, 1024, stdin);
if (NULL == ret)
{
if (feof (stdin))
printf ("concluding ...\n");
GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_FOREVER_REL, conclude_cb, NULL);
}
- else
- {
- GNUNET_SCHEDULER_shutdown ();
- }
return;
}
element->type = 0;
element->size = strlen(buf) + 1;
element->data = &element[1];
- strcpy((char *) &element[1], buf);
-
- GNUNET_CONSENSUS_insert (consensus, element, insert_done_cb, NULL);
+ strcpy ((char *) &element[1], buf);
+ GNUNET_CONSENSUS_insert (consensus, element, &insert_done_cb, element);
}
+
/**
* Called when a new element was received from another peer, or an error occured.
*
return GNUNET_YES;
}
+
/**
* Function run on shutdown to clean up.
*
static void
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "shutting down\n");
- if (NULL == consensus)
+ if (NULL != consensus)
{
- return;
+ GNUNET_CONSENSUS_destroy (consensus);
+ consensus = NULL;
}
-
- GNUNET_CONSENSUS_destroy (consensus);
}
{
struct GNUNET_CLIENT_TransmitHandle *th = cls;
struct GNUNET_TIME_Relative delay;
-
+
th->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ {
+ /* give up, was shutdown */
+ th->client->th = NULL;
+ th->notify (th->notify_cls, 0, NULL);
+ GNUNET_free (th);
+ return;
+ }
th->client->connection =
do_connect (th->client->service_name, th->client->cfg, th->client->attempts++);
th->client->first_message = GNUNET_YES;
delay = GNUNET_TIME_absolute_get_remaining (th->timeout);
delay.rel_value /= 2;
if ((GNUNET_YES != th->auto_retry) || (0 == --th->attempts_left) ||
- (delay.rel_value < 1))
+ (delay.rel_value < 1)||
+ (0 != (GNUNET_SCHEDULER_get_reason() & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Transmission failed %u times, giving up.\n",
GNUNET_SCHEDULER_cancel (speedup_task);
speedup_task = GNUNET_SCHEDULER_NO_TASK;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Stopped execution speed up\n");
+ if ((0 != interval.rel_value) && (0 != delta.rel_value))
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopped execution speed up\n");
}