[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r33315 - in gnunet: po src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r33315 - in gnunet: po src/util |
Date: |
Sat, 17 May 2014 19:39:50 +0200 |
Author: dold
Date: 2014-05-17 19:39:50 +0200 (Sat, 17 May 2014)
New Revision: 33315
Modified:
gnunet/po/POTFILES.in
gnunet/src/util/mq.c
gnunet/src/util/test_mq_client.c
Log:
add missing cancel implementation for MQ
Modified: gnunet/po/POTFILES.in
===================================================================
--- gnunet/po/POTFILES.in 2014-05-17 16:57:49 UTC (rev 33314)
+++ gnunet/po/POTFILES.in 2014-05-17 17:39:50 UTC (rev 33315)
@@ -232,6 +232,7 @@
src/peerstore/gnunet-peerstore.c
src/peerstore/gnunet-service-peerstore.c
src/peerstore/peerstore_api.c
+src/peerstore/peerstore_common.c
src/peerstore/plugin_peerstore_sqlite.c
src/postgres/postgres.c
src/psyc/gnunet-service-psyc.c
Modified: gnunet/src/util/mq.c
===================================================================
--- gnunet/src/util/mq.c 2014-05-17 16:57:49 UTC (rev 33314)
+++ gnunet/src/util/mq.c 2014-05-17 17:39:50 UTC (rev 33315)
@@ -94,6 +94,11 @@
GNUNET_MQ_DestroyImpl destroy_impl;
/**
+ * Implementation-dependent send cancel function
+ */
+ GNUNET_MQ_CancelImpl cancel_impl;
+
+ /**
* Implementation-specific state
*/
void *impl_state;
@@ -242,6 +247,8 @@
GNUNET_assert (NULL != mq);
GNUNET_assert (NULL == ev->parent_queue);
+ ev->parent_queue = mq;
+
/* is the implementation busy? queue it! */
if (NULL != mq->current_envelope)
{
@@ -276,6 +283,7 @@
* a message */
current_envelope = mq->current_envelope;
GNUNET_assert (NULL != current_envelope);
+ current_envelope->parent_queue = NULL;
if (NULL == mq->envelope_head)
{
mq->current_envelope = NULL;
@@ -337,6 +345,7 @@
mq = GNUNET_new (struct GNUNET_MQ_Handle);
mq->send_impl = send;
mq->destroy_impl = destroy;
+ mq->cancel_impl = cancel;
mq->handlers = handlers;
mq->handlers_cls = cls;
mq->impl_state = impl_state;
@@ -613,6 +622,17 @@
}
+static void
+connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq,
+ void *impl_state)
+{
+ struct ClientConnectionState *state = impl_state;
+ GNUNET_assert (NULL != state->th);
+ GNUNET_CLIENT_notify_transmit_ready_cancel (state->th);
+ state->th = NULL;
+}
+
+
struct GNUNET_MQ_Handle *
GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection
*connection,
const struct GNUNET_MQ_MessageHandler
*handlers,
@@ -633,6 +653,7 @@
mq->impl_state = state;
mq->send_impl = connection_client_send_impl;
mq->destroy_impl = connection_client_destroy_impl;
+ mq->cancel_impl = connection_client_cancel_impl;
if (NULL != handlers)
state->receive_requested = GNUNET_YES;
@@ -777,3 +798,45 @@
}
+/**
+ * Cancel sending the message. Message must have been sent with
+ * #GNUNET_MQ_send before. May not be called after the notify sent
+ * callback has been called
+ *
+ * @param ev queued envelope to cancel
+ */
+void
+GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
+{
+ struct GNUNET_MQ_Handle *mq = ev->parent_queue;
+
+ GNUNET_assert (NULL != mq);
+ GNUNET_assert (NULL != mq->cancel_impl);
+
+ if (mq->current_envelope == ev) {
+ // complex case, we already started with transmitting
+ // the message
+ mq->cancel_impl (mq, mq->impl_state);
+ // continue sending the next message, if any
+ if (NULL == mq->envelope_head)
+ {
+ mq->current_envelope = NULL;
+ }
+ else
+ {
+ mq->current_envelope = mq->envelope_head;
+ GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
+ mq->envelope_tail,
+ mq->current_envelope);
+ mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state);
+ }
+ } else {
+ // simple case, message is still waiting in the queue
+ GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev);
+ }
+
+ ev->parent_queue = NULL;
+ ev->mh = NULL;
+ GNUNET_free (ev);
+}
+
Modified: gnunet/src/util/test_mq_client.c
===================================================================
--- gnunet/src/util/test_mq_client.c 2014-05-17 16:57:49 UTC (rev 33314)
+++ gnunet/src/util/test_mq_client.c 2014-05-17 17:39:50 UTC (rev 33315)
@@ -102,7 +102,13 @@
notify = GNUNET_YES;
}
+static void
+send_trap_cb (void *cls)
+{
+ GNUNET_abort ();
+}
+
static void
test_mq (struct GNUNET_CLIENT_Connection *client)
{
@@ -116,10 +122,14 @@
GNUNET_MQ_send (mq, mqm);
mqm = GNUNET_MQ_msg_header (MY_TYPE);
+ GNUNET_MQ_notify_sent (mqm, send_trap_cb, NULL);
+ GNUNET_MQ_send (mq, mqm);
+ GNUNET_MQ_send_cancel (mqm);
+
+ mqm = GNUNET_MQ_msg_header (MY_TYPE);
GNUNET_MQ_notify_sent (mqm, send_cb, NULL);
GNUNET_MQ_send (mq, mqm);
- /* FIXME: add a message that will be canceled */
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r33315 - in gnunet: po src/util,
gnunet <=