[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r27070 - in gnunet/src: include nse testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r27070 - in gnunet/src: include nse testbed |
Date: |
Wed, 8 May 2013 17:03:32 +0200 |
Author: harsha
Date: 2013-05-08 17:03:32 +0200 (Wed, 08 May 2013)
New Revision: 27070
Modified:
gnunet/src/include/gnunet_testbed_logger_service.h
gnunet/src/nse/gnunet-service-nse.c
gnunet/src/testbed/test_testbed_logger_api.c
gnunet/src/testbed/testbed_logger_api.c
Log:
- have a timeout for cases where flushing takes too long
Modified: gnunet/src/include/gnunet_testbed_logger_service.h
===================================================================
--- gnunet/src/include/gnunet_testbed_logger_service.h 2013-05-08 14:26:24 UTC
(rev 27069)
+++ gnunet/src/include/gnunet_testbed_logger_service.h 2013-05-08 15:03:32 UTC
(rev 27070)
@@ -91,17 +91,21 @@
* Flush the buffered data to the logger service
*
* @param h the logger handle
+ * @param timeout how long to wait before calling the flust completion callback
* @param cb the callback to call after the data is flushed
* @param cb_cls the closure for the above callback
*/
void
GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h,
+ struct GNUNET_TIME_Relative timeout,
GNUNET_TESTBED_LOGGER_FlushCompletion cb,
void *cb_cls);
/**
- * Cancel notification upon flush.
+ * Cancel notification upon flush. Should only be used when the flush
+ * completion callback given to GNUNET_TESTBED_LOGGER_flush() is not already
+ * called.
*
* @param h the logger handle
*/
Modified: gnunet/src/nse/gnunet-service-nse.c
===================================================================
--- gnunet/src/nse/gnunet-service-nse.c 2013-05-08 14:26:24 UTC (rev 27069)
+++ gnunet/src/nse/gnunet-service-nse.c 2013-05-08 15:03:32 UTC (rev 27070)
@@ -1334,7 +1334,9 @@
my_private_key = NULL;
}
#if ENABLE_NSE_HISTOGRAM
- GNUNET_TESTBED_LOGGER_flush (lh, &flush_comp_cb, NULL); /* actual shutdown
delayed */
+ struct GNUNET_TIME_Relative timeout;
+ timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
+ GNUNET_TESTBED_LOGGER_flush (lh, timeout, &flush_comp_cb, NULL);
#endif
}
Modified: gnunet/src/testbed/test_testbed_logger_api.c
===================================================================
--- gnunet/src/testbed/test_testbed_logger_api.c 2013-05-08 14:26:24 UTC
(rev 27069)
+++ gnunet/src/testbed/test_testbed_logger_api.c 2013-05-08 15:03:32 UTC
(rev 27070)
@@ -183,7 +183,8 @@
GNUNET_TESTBED_LOGGER_write (h, buf, BSIZE);
if (0 == i++)
return;
- GNUNET_TESTBED_LOGGER_flush (h, &flush_comp, &write_task);
+ GNUNET_TESTBED_LOGGER_flush (h, GNUNET_TIME_UNIT_FOREVER_REL,
+ &flush_comp, &write_task);
}
Modified: gnunet/src/testbed/testbed_logger_api.c
===================================================================
--- gnunet/src/testbed/testbed_logger_api.c 2013-05-08 14:26:24 UTC (rev
27069)
+++ gnunet/src/testbed/testbed_logger_api.c 2013-05-08 15:03:32 UTC (rev
27070)
@@ -92,6 +92,9 @@
*/
struct GNUNET_CLIENT_Connection *client;
+ /**
+ * The transport handle
+ */
struct GNUNET_CLIENT_TransmitHandle *th;
/**
@@ -104,23 +107,63 @@
*/
struct MessageQueue *mq_tail;
- GNUNET_SCHEDULER_TaskIdentifier flush_completion_task;
-
+ /**
+ * Flush completion callback
+ */
GNUNET_TESTBED_LOGGER_FlushCompletion cb;
+ /**
+ * Closure for the above callback
+ */
void *cb_cls;
+ /**
+ * Local buffer for data to be transmitted
+ */
void *buf;
+ /**
+ * The size of the local buffer
+ */
size_t bs;
+ /**
+ * Number of bytes wrote since last flush
+ */
size_t bwrote;
+ /**
+ * How long after should we retry sending a message to the service?
+ */
struct GNUNET_TIME_Relative retry_backoff;
+
+ /**
+ * Task to call the flush completion callback
+ */
+ GNUNET_SCHEDULER_TaskIdentifier flush_completion_task;
+
+ /**
+ * Task to be executed when flushing takes too long
+ */
+ GNUNET_SCHEDULER_TaskIdentifier timeout_flush_task;
};
/**
+ * Cancels the flush timeout task
+ *
+ * @param
+ * @return
+ */
+static void
+cancel_timeout_flush (struct GNUNET_TESTBED_LOGGER_Handle *h)
+{
+ GNUNET_SCHEDULER_cancel (h->timeout_flush_task);
+ h->timeout_flush_task = GNUNET_SCHEDULER_NO_TASK;
+}
+
+
+/**
* Task to call the flush completion notification
*
* @param cls the logger handle
@@ -129,7 +172,7 @@
static void
call_flush_completion (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
- struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
+ struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
GNUNET_TESTBED_LOGGER_FlushCompletion cb;
void *cb_cls;
size_t bw;
@@ -141,6 +184,8 @@
h->cb = NULL;
cb_cls = h->cb_cls;
h->cb_cls = NULL;
+ if (GNUNET_SCHEDULER_NO_TASK != h->timeout_flush_task)
+ cancel_timeout_flush (h);
if (NULL != cb)
cb (cb_cls, bw);
}
@@ -355,19 +400,54 @@
/**
+ * Task to be executed when flushing our local buffer takes longer than timeout
+ * given to GNUNET_TESTBED_LOGGER_flush(). The flush completion callback will
+ * be called with 0 as the amount of data sent.
+ *
+ * @param cls the logger handle
+ * @param tc scheduler task context
+ */
+static void
+timeout_flush (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
+ GNUNET_TESTBED_LOGGER_FlushCompletion cb;
+ void *cb_cls;
+
+ h->timeout_flush_task = GNUNET_SCHEDULER_NO_TASK;
+ cb = h->cb;
+ h->cb = NULL;
+ cb_cls = h->cb_cls;
+ h->cb_cls = NULL;
+ if (GNUNET_SCHEDULER_NO_TASK != h->flush_completion_task)
+ {
+ GNUNET_SCHEDULER_cancel (h->flush_completion_task);
+ h->flush_completion_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (NULL != cb)
+ cb (cb_cls, 0);
+}
+
+
+/**
* Flush the buffered data to the logger service
*
* @param h the logger handle
+ * @param timeout how long to wait before calling the flust completion callback
* @param cb the callback to call after the data is flushed
* @param cb_cls the closure for the above callback
*/
void
GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h,
+ struct GNUNET_TIME_Relative timeout,
GNUNET_TESTBED_LOGGER_FlushCompletion cb,
void *cb_cls)
{
h->cb = cb;
h->cb_cls = cb_cls;
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->timeout_flush_task);
+ h->timeout_flush_task =
+ GNUNET_SCHEDULER_add_delayed (timeout, &timeout_flush, h);
if (NULL == h->buf)
{
trigger_flush_notification (h);
@@ -378,7 +458,9 @@
/**
- * Cancel notification upon flush.
+ * Cancel notification upon flush. Should only be used when the flush
+ * completion callback given to GNUNET_TESTBED_LOGGER_flush() is not already
+ * called.
*
* @param h the logger handle
*/
@@ -390,6 +472,8 @@
GNUNET_SCHEDULER_cancel (h->flush_completion_task);
h->flush_completion_task = GNUNET_SCHEDULER_NO_TASK;
}
+ if (GNUNET_SCHEDULER_NO_TASK != h->timeout_flush_task)
+ cancel_timeout_flush (h);
h->cb = NULL;
h->cb_cls = NULL;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r27070 - in gnunet/src: include nse testbed,
gnunet <=