- verboser log, faster start
[oweals/gnunet.git] / src / transport / plugin_transport_unix.c
index fee1c58c0cec400347bf8413f63d6409978dc9ed..940582d1e2e45f6988c2fcf252f71d519018c530 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,
@@ -548,8 +548,14 @@ resend:
 
   if (GNUNET_SYSERR == sent)
   {
-    if ((errno == EAGAIN) || (errno == ENOBUFS))
+    if (errno == EAGAIN)
+    {
+      return RETRY; /* We have to retry later  */
+    }
+    if (errno == ENOBUFS)
+    {
       return RETRY; /* We have to retry later  */
+    }
     if (errno == EMSGSIZE)
     {
       socklen_t size = 0;
@@ -584,6 +590,7 @@ resend:
       }
     }
   }
+
   LOG (GNUNET_ERROR_TYPE_DEBUG,
               "UNIX transmit %u-byte message to %s (%d: %s)\n",
               (unsigned int) msgbuf_size, GNUNET_a2s (sb, sbs), (int) sent,
@@ -734,7 +741,7 @@ unix_plugin_send (void *cls,
     return GNUNET_SYSERR;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending %u bytes with session for peer `%s' `%s'\n",
-               msgbuf_size,
+                msgbuf_size,
         GNUNET_i2s (&session->target),
         (char *) session->addr);
 
@@ -753,7 +760,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;
@@ -894,9 +901,37 @@ unix_plugin_select_read (struct Plugin * plugin)
 static void
 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 */
+            LOG (GNUNET_ERROR_TYPE_DEBUG,
+              "Timeout for message with %llu bytes \n", msgw->msgsize);
+          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,
@@ -910,21 +945,13 @@ unix_plugin_select_write (struct Plugin * plugin)
                          msgw->payload,
                          msgw->cont, msgw->cont_cls);
 
-  if (0 == sent)
+  if (RETRY == sent)
   {
-      retry_counter ++;
-      if (retry_counter <= MAX_RETRIES)
-      {
-        GNUNET_STATISTICS_update (plugin->env->stats,"# UNIX retry attempts",
-              1, GNUNET_NO);
-        return; /* retry */
-      }
-      else
-        sent = GNUNET_SYSERR; /* abort */
-  }
-  retry_counter = 0;
+    GNUNET_STATISTICS_update (plugin->env->stats,"# UNIX retry attempts",
+          1, GNUNET_NO);
 
-  if (GNUNET_SYSERR == sent)
+  }
+  else if (GNUNET_SYSERR == sent)
   {
     /* failed and no retry */
     if (NULL != msgw->cont)
@@ -944,8 +971,7 @@ unix_plugin_select_write (struct Plugin * plugin)
     GNUNET_free (msgw);
     return;
   }
-
-  else if (sent >= 0)
+  else if (sent > 0)
   {
     /* successfully sent bytes */
     if (NULL != msgw->cont)
@@ -965,8 +991,6 @@ unix_plugin_select_write (struct Plugin * plugin)
     GNUNET_free (msgw);
     return;
   }
-
-
 }