improve unix timeout behaviour
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 14 Nov 2012 14:09:43 +0000 (14:09 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 14 Nov 2012 14:09:43 +0000 (14:09 +0000)
src/transport/plugin_transport_unix.c
src/transport/test_transport_api_unreliability.c

index fee1c58c0cec400347bf8413f63d6409978dc9ed..d9badf38030365eb9bbdead54d04d1b158ef1570 100644 (file)
@@ -108,7 +108,7 @@ struct UNIXMessageWrapper
   size_t msgsize;
   size_t payload;
 
-  struct GNUNET_TIME_Relative timeout;
+  struct GNUNET_TIME_Absolute timeout;
   unsigned int priority;
 
   struct Session *session;
@@ -495,7 +495,7 @@ unix_real_send (void *cls,
                 struct GNUNET_NETWORK_Handle *send_handle,
                 const struct GNUNET_PeerIdentity *target, const char *msgbuf,
                 size_t msgbuf_size, unsigned int priority,
-                struct GNUNET_TIME_Relative timeout,
+                struct GNUNET_TIME_Absolute timeout,
                 const void *addr,
                 size_t addrlen,
                 size_t payload,
@@ -753,7 +753,7 @@ unix_plugin_send (void *cls,
   wrapper->msgsize = ssize;
   wrapper->payload = msgbuf_size;
   wrapper->priority = priority;
-  wrapper->timeout = to;
+  wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), to);
   wrapper->cont = cont;
   wrapper->cont_cls = cont_cls;
   wrapper->session = session;
@@ -896,7 +896,35 @@ unix_plugin_select_write (struct Plugin * plugin)
 {
   static int retry_counter = 0;
   int sent = 0;
-  struct UNIXMessageWrapper * msgw = plugin->msg_head;
+
+
+  struct UNIXMessageWrapper * msgw = plugin->msg_tail;
+  while (NULL != msgw)
+  {
+      if (GNUNET_TIME_absolute_get_remaining (msgw->timeout).rel_value > 0)
+        break; /* Message is ready for sending */
+      else
+      {
+          /* Message has a timeout */
+          GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
+          if (NULL != msgw->cont)
+            msgw->cont (msgw->cont_cls, &msgw->session->target, GNUNET_SYSERR, msgw->payload, 0);
+
+          plugin->bytes_in_queue -= msgw->msgsize;
+          GNUNET_STATISTICS_set (plugin->env->stats, "# bytes currently in UNIX buffers",
+              plugin->bytes_in_queue, GNUNET_NO);
+
+          plugin->bytes_discarded += msgw->msgsize;
+          GNUNET_STATISTICS_set (plugin->env->stats,"# UNIX bytes discarded",
+              plugin->bytes_discarded, GNUNET_NO);
+
+          GNUNET_free (msgw->msg);
+          GNUNET_free (msgw);
+      }
+      msgw = plugin->msg_tail;
+  }
+  if (NULL == msgw)
+    return; /* Nothing to send at the moment */
 
   sent = unix_real_send (plugin,
                          plugin->unix_sock.desc,
@@ -965,8 +993,6 @@ unix_plugin_select_write (struct Plugin * plugin)
     GNUNET_free (msgw);
     return;
   }
-
-
 }
 
 
index f1e249cdb6bfe14ebb63a4f6504ed7e1e96c181a..73158e59c24e11dcb0e36454f5c1e83f7472a065 100644 (file)
@@ -447,7 +447,7 @@ static void
 sendtask ()
 {
   start_time = GNUNET_TIME_absolute_get ();
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting to send %u messages\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to send %u messages\n",
               TOTAL_MSGS);
   th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), 0,
                                                TIMEOUT_TRANSMIT, &notify_ready,