[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25296 - in gnunet/src: arm consensus util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25296 - in gnunet/src: arm consensus util |
Date: |
Thu, 6 Dec 2012 14:53:33 +0100 |
Author: grothoff
Date: 2012-12-06 14:53:33 +0100 (Thu, 06 Dec 2012)
New Revision: 25296
Modified:
gnunet/src/arm/gnunet-arm.c
gnunet/src/consensus/gnunet-consensus.c
gnunet/src/util/client.c
gnunet/src/util/speedup.c
Log:
-improving shutdown behavior
Modified: gnunet/src/arm/gnunet-arm.c
===================================================================
--- gnunet/src/arm/gnunet-arm.c 2012-12-06 13:33:27 UTC (rev 25295)
+++ gnunet/src/arm/gnunet-arm.c 2012-12-06 13:53:33 UTC (rev 25296)
@@ -128,12 +128,12 @@
/**
* 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;
/**
@@ -206,8 +206,7 @@
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);
}
@@ -237,6 +236,50 @@
/**
+ * 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.
*
* @param cls closure
@@ -264,39 +307,13 @@
ret = 1;
return;
}
- GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &shutdown_task, NULL);
+ 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.
*
@@ -306,6 +323,10 @@
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++)
@@ -393,9 +414,7 @@
}
/* Fall through */
default: /* last phase */
- GNUNET_ARM_disconnect (h);
- if ((end == GNUNET_YES) && (delete == GNUNET_YES))
- delete_files ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
}
Modified: gnunet/src/consensus/gnunet-consensus.c
===================================================================
--- gnunet/src/consensus/gnunet-consensus.c 2012-12-06 13:33:27 UTC (rev
25295)
+++ gnunet/src/consensus/gnunet-consensus.c 2012-12-06 13:53:33 UTC (rev
25296)
@@ -48,13 +48,7 @@
*/
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);
@@ -76,23 +70,22 @@
}
-
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);
}
@@ -107,10 +100,12 @@
{
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))
@@ -118,10 +113,6 @@
printf ("concluding ...\n");
GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_FOREVER_REL,
conclude_cb, NULL);
}
- else
- {
- GNUNET_SCHEDULER_shutdown ();
- }
return;
}
@@ -131,11 +122,11 @@
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.
*
@@ -157,6 +148,7 @@
return GNUNET_YES;
}
+
/**
* Function run on shutdown to clean up.
*
@@ -166,14 +158,12 @@
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);
}
Modified: gnunet/src/util/client.c
===================================================================
--- gnunet/src/util/client.c 2012-12-06 13:33:27 UTC (rev 25295)
+++ gnunet/src/util/client.c 2012-12-06 13:53:33 UTC (rev 25296)
@@ -943,8 +943,16 @@
{
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;
@@ -1006,7 +1014,8 @@
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",
Modified: gnunet/src/util/speedup.c
===================================================================
--- gnunet/src/util/speedup.c 2012-12-06 13:33:27 UTC (rev 25295)
+++ gnunet/src/util/speedup.c 2012-12-06 13:53:33 UTC (rev 25296)
@@ -83,8 +83,9 @@
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");
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25296 - in gnunet/src: arm consensus util,
gnunet <=