gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r9268 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r9268 - gnunet/src/util
Date: Sat, 24 Oct 2009 16:17:58 -0600

Author: grothoff
Date: 2009-10-24 16:17:58 -0600 (Sat, 24 Oct 2009)
New Revision: 9268

Modified:
   gnunet/src/util/client.c
   gnunet/src/util/connection.c
Log:
do propper delaying of notification past return

Modified: gnunet/src/util/client.c
===================================================================
--- gnunet/src/util/client.c    2009-10-24 21:49:17 UTC (rev 9267)
+++ gnunet/src/util/client.c    2009-10-24 22:17:58 UTC (rev 9268)
@@ -674,6 +674,7 @@
   size_t ret;
   struct GNUNET_TIME_Relative delay;
   
+  th->th = NULL;
   if (buf == NULL)
     {
       delay = GNUNET_TIME_absolute_get_remaining (th->timeout);
@@ -691,7 +692,6 @@
       /* auto-retry */
       GNUNET_CONNECTION_destroy (th->sock->sock);
       th->sock->sock = NULL;
-      th->th = NULL;
       delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS);
       th->task = GNUNET_SCHEDULER_add_delayed (th->sock->sched,
                                               GNUNET_NO,
@@ -771,8 +771,11 @@
 GNUNET_CLIENT_notify_transmit_ready_cancel (struct 
GNUNET_CLIENT_TransmitHandle *th)
 {
   if (th->task != GNUNET_SCHEDULER_NO_TASK)
-    GNUNET_SCHEDULER_cancel (th->sock->sched,
-                            th->task);
+    {
+      GNUNET_break (NULL == th->th);
+      GNUNET_SCHEDULER_cancel (th->sock->sched,
+                              th->task);      
+    }
   else
     {
       GNUNET_break (NULL != th->th);

Modified: gnunet/src/util/connection.c
===================================================================
--- gnunet/src/util/connection.c        2009-10-24 21:49:17 UTC (rev 9267)
+++ gnunet/src/util/connection.c        2009-10-24 22:17:58 UTC (rev 9268)
@@ -1293,7 +1293,33 @@
 }
 
 
+/**
+ * Task invoked by the scheduler when we failed to connect
+ * at the time of being asked to transmit.
+ *
+ * This task notifies the client about the error.
+ */
 static void
+connect_error (void *cls,
+              const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GNUNET_CONNECTION_Handle *sock = cls;
+  GNUNET_CONNECTION_TransmitReadyNotify notify;
+
+#if DEBUG_CONNECTION
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Transmission request of size %u fails, connection failed 
(%p).\n",
+             sock->nth.notify_size,
+             sock);
+#endif
+  sock->write_task = GNUNET_SCHEDULER_NO_TASK;
+  notify = sock->nth.notify_ready;
+  sock->nth.notify_ready = NULL;
+  notify (sock->nth.notify_ready_cls, 0, NULL);
+}
+
+
+static void
 transmit_error (struct GNUNET_CONNECTION_Handle *sock)
 {
   GNUNET_CONNECTION_TransmitReadyNotify notify;
@@ -1455,20 +1481,6 @@
     return NULL;
   GNUNET_assert (notify != NULL);
   GNUNET_assert (sock->write_buffer_size >= size);
-
-  if ( (sock->sock == NULL) &&
-       (sock->ap_head == NULL) &&
-       (sock->dns_active != GNUNET_YES) )
-    {
-#if DEBUG_CONNECTION
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Transmission request of size %u fails, connection failed 
(%p).\n",
-                 size,
-                 sock);
-#endif
-      notify (notify_cls, 0, NULL);
-      return &sock->nth;
-    }
   GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size);
   GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size);
   GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_off);
@@ -1478,6 +1490,19 @@
   sock->nth.notify_size = size;
   sock->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout);
   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task);
+  if ( (sock->sock == NULL) &&
+       (sock->ap_head == NULL) &&
+       (sock->dns_active != GNUNET_YES) )
+    {     
+      sock->write_task = GNUNET_SCHEDULER_add_delayed (sock->sched,
+                                                      GNUNET_NO,
+                                                      
GNUNET_SCHEDULER_PRIORITY_KEEP,
+                                                      GNUNET_SCHEDULER_NO_TASK,
+                                                      GNUNET_TIME_UNIT_ZERO,
+                                                      &connect_error,
+                                                      sock);
+      return &sock->nth;
+    }
   if (GNUNET_SCHEDULER_NO_TASK != sock->write_task)
     return &sock->nth;
   if (sock->sock != NULL)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]