[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r26913 - gnunet/src/set
From: |
gnunet |
Subject: |
[GNUnet-SVN] r26913 - gnunet/src/set |
Date: |
Wed, 17 Apr 2013 12:41:37 +0200 |
Author: dold
Date: 2013-04-17 12:41:37 +0200 (Wed, 17 Apr 2013)
New Revision: 26913
Modified:
gnunet/src/set/mq.h
gnunet/src/set/set.h
gnunet/src/set/set_api.c
Log:
fix
Modified: gnunet/src/set/mq.h
===================================================================
--- gnunet/src/set/mq.h 2013-04-17 09:41:59 UTC (rev 26912)
+++ gnunet/src/set/mq.h 2013-04-17 10:41:37 UTC (rev 26913)
@@ -56,7 +56,11 @@
void
GNUNET_MQ_send (struct GNUNET_MQ_MessageQueue *mq, struct GNUNET_MQ_Message
*mqm);
+
void *
+GNUNET_MQ_assoc_get (struct GNUNET_MQ_MessageQueue *mq, uint32_t request_id);
+
+void *
GNUNET_MQ_assoc_remove (struct GNUNET_MQ_MessageQueue *mq, uint32_t
request_id);
uint32_t
Modified: gnunet/src/set/set.h
===================================================================
--- gnunet/src/set/set.h 2013-04-17 09:41:59 UTC (rev 26912)
+++ gnunet/src/set/set.h 2013-04-17 10:41:37 UTC (rev 26913)
@@ -88,9 +88,6 @@
* request id of the request we want to accept
*/
uint32_t request_id GNUNET_PACKED;
-
-
- struct GNUNET_TIME_RelativeNBO timeout;
};
@@ -126,8 +123,6 @@
struct GNUNET_HashCode app_id;
- struct GNUNET_TIME_RelativeNBO timeout;
-
/**
* id of our evaluate
*/
Modified: gnunet/src/set/set_api.c
===================================================================
--- gnunet/src/set/set_api.c 2013-04-17 09:41:59 UTC (rev 26912)
+++ gnunet/src/set/set_api.c 2013-04-17 10:41:37 UTC (rev 26913)
@@ -60,6 +60,7 @@
void *result_cls;
struct GNUNET_SET_Handle *set;
uint32_t request_id;
+ GNUNET_SCHEDULER_TaskIdentifier timeout_task;
};
@@ -75,6 +76,12 @@
};
+/**
+ * Handle result message for a set operation.
+ *
+ * @param cls the set
+ * @param mh the message
+ */
void
handle_result (void *cls, struct GNUNET_MessageHeader *mh)
{
@@ -90,20 +97,34 @@
GNUNET_MQ_send (set->mq, mqm);
}
- oh = GNUNET_MQ_assoc_remove (set->mq, ntohl (msg->request_id));
+ oh = GNUNET_MQ_assoc_get (set->mq, ntohl (msg->request_id));
GNUNET_break (NULL != oh);
+ if (GNUNET_SCHEDULER_NO_TASK != oh->timeout_task)
+ {
+ GNUNET_SCHEDULER_cancel (oh->timeout_task);
+ oh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (htons (msg->result_status) != GNUNET_SET_STATUS_OK)
{
- oh->result_cb (oh->result_cls, NULL, htons (msg->result_status));
+ if (NULL != oh->result_cb)
+ oh->result_cb (oh->result_cls, NULL, htons (msg->result_status));
+ GNUNET_MQ_assoc_remove (set->mq, ntohl (msg->request_id));
GNUNET_free (oh);
return;
}
e.data = &msg[1];
e.size = ntohs (mh->size) - sizeof (struct ResultMessage);
e.type = msg->element_type;
- oh->result_cb (oh->result_cls, &e, htons (msg->result_status));
+ if (NULL != oh->result_cb)
+ oh->result_cb (oh->result_cls, &e, htons (msg->result_status));
}
+/**
+ * Handle request message for a listen operation
+ *
+ * @param cls the listen handle
+ * @param mh the message
+ */
void
handle_request (void *cls, struct GNUNET_MessageHeader *mh)
{
@@ -221,6 +242,12 @@
set->mq = NULL;
}
+
+/**
+ * Destroy an operation handle
+ *
+ * @cls closure, the operation handle
+ */
static void
operation_destroy (void *cls)
{
@@ -229,10 +256,32 @@
oh_assoc = GNUNET_MQ_assoc_remove (oh->set->mq, oh->request_id);
GNUNET_assert (oh_assoc == oh);
+ oh->set = NULL;
+ GNUNET_free (oh);
}
/**
+ * Signature of the main function of a task.
+ *
+ * @param cls closure
+ * @param tc context information (why was this task triggered now)
+ */
+static void
+operation_timeout_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext * tc)
+{
+ struct GNUNET_SET_OperationHandle *oh = cls;
+ oh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ if (NULL != oh->result_cb)
+ oh->result_cb (oh->result_cls, NULL, GNUNET_SET_STATUS_TIMEOUT);
+ oh->result_cb = NULL;
+ oh->result_cls = NULL;
+ GNUNET_SET_operation_cancel (oh);
+}
+
+
+/**
* Evaluate a set operation with our set and the set of another peer.
*
* @param set set to use
@@ -266,9 +315,9 @@
msg->request_id = htonl (GNUNET_MQ_assoc_add (set->mq, mqm, oh));
msg->other_peer = *other_peer;
msg->app_id = *app_id;
- msg->timeout = GNUNET_TIME_relative_hton (timeout);
memcpy (&msg[1], context_msg, htons (context_msg->size));
- GNUNET_MQ_notify_timeout (mqm, operation_destroy, oh);
+ oh->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
operation_timeout_task, oh);
+ /* destroy the operation if the queue gets destroyed */
GNUNET_MQ_notify_destroy (mqm, operation_destroy, oh);
GNUNET_MQ_send (set->mq, mqm);
@@ -366,9 +415,9 @@
oh->set = set;
mqm = GNUNET_MQ_msg (msg , GNUNET_MESSAGE_TYPE_SET_ACCEPT);
- msg->timeout = GNUNET_TIME_relative_hton (timeout);
msg->request_id = htonl (request->request_id);
- GNUNET_MQ_notify_timeout (mqm, operation_destroy, oh);
+ oh->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
operation_timeout_task, oh);
+ /* destroy the operation if the queue gets destroyed */
GNUNET_MQ_notify_destroy (mqm, operation_destroy, oh);
GNUNET_MQ_send (set->mq, mqm);
@@ -391,5 +440,6 @@
GNUNET_assert (h_assoc == h);
mqm = GNUNET_MQ_msg_raw (GNUNET_MESSAGE_TYPE_SET_CANCEL);
GNUNET_MQ_send (h->set->mq, mqm);
+ GNUNET_free (h);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r26913 - gnunet/src/set,
gnunet <=