backup errno
[oweals/gnunet.git] / src / transport / transport_api.c
index 49462fd5db79de9678e43a9f5d32fbfd22fd4844..8d08f82d9d3f516796604a662dcc9b977b3992af 100644 (file)
@@ -390,8 +390,15 @@ transport_notify_ready (void *cls, size_t size, void *buf)
           GNUNET_assert (n->transmit_handle == th);
           n->transmit_handle = NULL;
         }
+      if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
+       {
+         GNUNET_SCHEDULER_cancel (h->sched,
+                                  th->notify_delay_task);
+         th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
+       }
       GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL));
       GNUNET_free (th);
+      if (h->connect_ready_head != NULL) schedule_transmission (h); /* FIXME: is this ok? */
       return 0;
     } 
 #if DEBUG_TRANSPORT
@@ -407,8 +414,6 @@ transport_notify_ready (void *cls, size_t size, void *buf)
       th = h->connect_ready_head;
       if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
        {
-         /* remove existing time out task (only applies if
-            this is not the first iteration of the loop) */
          GNUNET_SCHEDULER_cancel (h->sched,
                                   th->notify_delay_task);
          th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
@@ -569,7 +574,7 @@ try_connect (struct GNUNET_TRANSPORT_TransmitHandle *th);
  * TransmitHandle.
  */
 static void
-transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+peer_transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GNUNET_TRANSPORT_TransmitHandle *th = cls;
 
@@ -622,7 +627,7 @@ schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h,
                                    GNUNET_SCHEDULER_PRIORITY_KEEP,
                                    GNUNET_SCHEDULER_NO_TASK,
                                    timeout,
-                                   &transmit_timeout, th);    
+                                   &peer_transmit_timeout, th);    
   if (at_head)
     {
       th->next = h->connect_ready_head;
@@ -989,6 +994,11 @@ request_connect (void *cls, size_t size, void *buf)
                  "TRY_CONNECT",
                  GNUNET_i2s(&th->target));
 #endif
+      if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
+       {
+         GNUNET_SCHEDULER_cancel (h->sched, th->notify_delay_task);
+         th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
+       }
       th->notify (th->notify_cls, 0, NULL);
       GNUNET_free (th);
       return 0;
@@ -1011,7 +1021,7 @@ request_connect (void *cls, size_t size, void *buf)
                                     GNUNET_SCHEDULER_NO_TASK,
                                    GNUNET_TIME_absolute_get_remaining
                                    (th->timeout),
-                                   &transmit_timeout, th);
+                                   &peer_transmit_timeout, th);
   insert_transmit_handle (&h->connect_wait_head, th);
   return sizeof (struct TryConnectMessage);
 }
@@ -1104,7 +1114,7 @@ remove_neighbour (struct GNUNET_TRANSPORT_Handle *h,
        {
          /* signal error */
          GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->notify_delay_task);
-         transmit_timeout (th, NULL);    
+         peer_transmit_timeout (th, NULL);       
        }
       else
        {
@@ -1140,6 +1150,9 @@ reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct GNUNET_TRANSPORT_TransmitHandle *pos;
   struct NeighbourList *n;
 
+  fprintf (stderr,
+          "Trying to reconnect to transport!\n");
+
   /* Forget about all neighbours that we used to be connected
      to */
   while (NULL != (n = h->neighbours))
@@ -1326,7 +1339,7 @@ schedule_request (struct GNUNET_TRANSPORT_TransmitHandle *th)
                                         GNUNET_SCHEDULER_PRIORITY_KEEP,
                                         GNUNET_SCHEDULER_NO_TASK,
                                         GNUNET_TIME_absolute_get_remaining
-                                        (th->timeout), &transmit_timeout, th);
+                                        (th->timeout), &peer_transmit_timeout, th);
       return;
     }
   n->transmit_ok = GNUNET_NO;
@@ -1488,11 +1501,13 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle)
   struct GNUNET_CLIENT_Connection *client;
 
 #if DEBUG_TRANSPORT
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+             "Transport disconnect called!\n");
 #endif
   while (NULL != (th = handle->connect_ready_head))
     {
       handle->connect_ready_head = th->next;
+      GNUNET_assert (th->notify_delay_task == GNUNET_SCHEDULER_NO_TASK);
       th->notify (th->notify_cls, 0, NULL);
       GNUNET_free (th);
     }
@@ -1589,7 +1604,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
                                                GNUNET_SCHEDULER_PRIORITY_KEEP,
                                                GNUNET_SCHEDULER_NO_TASK,
                                                GNUNET_TIME_absolute_get_remaining(th->timeout),
-                                               &transmit_timeout, 
+                                               &peer_transmit_timeout, 
                                                th);    
             }
           GNUNET_CLIENT_disconnect (h->client);
@@ -1932,7 +1947,7 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
                                        GNUNET_NO,
                                        GNUNET_SCHEDULER_PRIORITY_KEEP,
                                        GNUNET_SCHEDULER_NO_TASK,
-                                       timeout, &transmit_timeout, th);
+                                       timeout, &peer_transmit_timeout, th);
       return th;
     }
   
@@ -1947,8 +1962,7 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
 
 
 /**
- * Cancel the specified transmission-ready
- * notification.
+ * Cancel the specified transmission-ready notification.
  */
 void
 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
@@ -1973,6 +1987,7 @@ GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
       h->transmission_scheduled = GNUNET_NO;
     }
   GNUNET_free (th->notify_cls);
+  GNUNET_assert (th->notify_delay_task == GNUNET_SCHEDULER_NO_TASK);
   GNUNET_free (th);
 }