eliminate DHT PUT OK message by using MQ feature of calling continuation when transmi...
[oweals/gnunet.git] / src / util / mq.c
index 4984df76c4e237d53010495e3f5f5110822db43a..dbcce704dca500676974fd588fb435258d240216 100644 (file)
 
 #define LOG(kind,...) GNUNET_log_from (kind, "util-mq",__VA_ARGS__)
 
-//#if HAVE_EXECINFO_H
-//#include "execinfo.h"
-
-///**
-// * Use lsof to generate file descriptor reports on select error?
-// * (turn off for stable releases).
-// */
-//#define USE_LSOF GNUNET_NO
-
-///**
-// * Obtain trace information for all scheduler calls that schedule tasks.
-// */
-//#define EXECINFO GNUNET_NO
-
-///**
-// * Check each file descriptor before adding
-// */
-//#define DEBUG_FDS GNUNET_NO
-
-///**
-// * Depth of the traces collected via EXECINFO.
-// */
-//#define MAX_TRACE_DEPTH 50
-//#endif
 
 struct GNUNET_MQ_Envelope
 {
@@ -85,7 +61,7 @@ struct GNUNET_MQ_Envelope
   GNUNET_SCHEDULER_TaskCallback sent_cb;
 
   /**
-   * Closure for @e sent_cb
+   * Closure for @e send_cb
    */
   void *sent_cls;
 
@@ -245,10 +221,8 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq,
   uint16_t mtype = ntohs (mh->type);
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Queue %p received message of type %u and size %u\n",
-       mq,
-       mtype,
-       msize);
+       "Received message of type %u and size %u\n",
+       mtype, msize);
 
   if (NULL == mq->handlers)
     goto done;
@@ -384,10 +358,10 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq,
   GNUNET_assert (NULL == mq->envelope_head);
   mq->current_envelope = ev;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "mq: sending message of type %u, queue empty (MQ: %p)\n",
-              ntohs(ev->mh->type),
-              mq);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "sending message of type %u, queue empty (MQ: %p)\n",
+       ntohs(ev->mh->type),
+       mq);
 
   mq->send_impl (mq,
                 ev->mh,
@@ -485,9 +459,9 @@ impl_send_continue (void *cls)
                               mq->envelope_tail,
                               mq->current_envelope);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "mq: sending message of type %u from queue\n",
-              ntohs(mq->current_envelope->mh->type));
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "sending message of type %u from queue\n",
+       ntohs(mq->current_envelope->mh->type));
 
   mq->send_impl (mq,
                 mq->current_envelope->mh,
@@ -604,11 +578,9 @@ void
 GNUNET_MQ_set_handlers_closure (struct GNUNET_MQ_Handle *mq,
                                 void *handlers_cls)
 {
-  unsigned int i;
-
   if (NULL == mq->handlers)
     return;
-  for (i=0;NULL != mq->handlers[i].cb; i++)
+  for (unsigned int i=0;NULL != mq->handlers[i].cb; i++)
     mq->handlers[i].cls = handlers_cls;
 }
 
@@ -808,7 +780,9 @@ GNUNET_MQ_notify_sent (struct GNUNET_MQ_Envelope *ev,
                        GNUNET_SCHEDULER_TaskCallback cb,
                        void *cb_cls)
 {
-  GNUNET_assert (NULL == ev->sent_cb);
+  /* allow setting *OR* clearing callback */
+  GNUNET_assert ( (NULL == ev->sent_cb) ||
+                  (NULL == cb) );
   ev->sent_cb = cb;
   ev->sent_cls = cb_cls;
 }
@@ -877,9 +851,9 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
                                 ev);
     GNUNET_assert (0 < mq->queue_length);
     mq->queue_length--;
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "MQ destroy drops message of type %u\n",
-                ntohs (ev->mh->type));
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "MQ destroy drops message of type %u\n",
+         ntohs (ev->mh->type));
     GNUNET_MQ_discard (ev);
   }
   if (NULL != mq->current_envelope)
@@ -887,21 +861,9 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
     /* we can only discard envelopes that
      * are not queued! */
     mq->current_envelope->parent_queue = NULL;
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "MQ destroy drops current message of type %u\n",
-                ntohs (mq->current_envelope->mh->type));
-//#if EXECINFO
-//  void *backtrace_array[MAX_TRACE_DEPTH];
-//  int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
-//    char **backtrace_strings =
-//        backtrace_symbols (backtrace_array,
-//         t->num_backtrace_strings);
-//    for (unsigned int i = 0; i < num_backtrace_strings; i++)
-//      LOG (GNUNET_ERROR_TYPE_DEBUG,
-//     "client drop trace %u: %s\n",
-//     i,
-//     backtrace_strings[i]);
-//#endif
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "MQ destroy drops current message of type %u\n",
+         ntohs (mq->current_envelope->mh->type));
     GNUNET_MQ_discard (mq->current_envelope);
     mq->current_envelope = NULL;
     GNUNET_assert (0 < mq->queue_length);
@@ -984,9 +946,9 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
                                    mq->envelope_tail,
                                    mq->current_envelope);
 
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "mq: sending canceled message of type %u queue\n",
-                  ntohs(ev->mh->type));
+      LOG (GNUNET_ERROR_TYPE_DEBUG,
+           "sending canceled message of type %u queue\n",
+           ntohs(ev->mh->type));
 
       mq->send_impl (mq,
                     mq->current_envelope->mh,