MinGW
[oweals/gnunet.git] / src / util / connection.c
index c572d02de71427d09a8c089555dec50bd9aac814..22a75691bead5905575b796a9edb748d8c723f8b 100644 (file)
@@ -931,11 +931,6 @@ void
 GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock,
                           int finish_pending_write)
 {
-  if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL))
-    {
-      GNUNET_RESOLVER_request_cancel (sock->dns_active);
-      sock->dns_active = NULL;
-    }
   if (GNUNET_NO == finish_pending_write)
     {
       if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
@@ -943,8 +938,14 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock,
          GNUNET_SCHEDULER_cancel (sock->sched,
                                   sock->write_task);
          sock->write_task = GNUNET_SCHEDULER_NO_TASK;
+         sock->write_buffer_off = 0;
        }
     }
+  if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL))
+    {
+      GNUNET_RESOLVER_request_cancel (sock->dns_active);
+      sock->dns_active = NULL;
+    }
   GNUNET_assert (sock->sched != NULL);
   GNUNET_SCHEDULER_add_now (sock->sched,
                            &destroy_continuation, sock);
@@ -1538,8 +1539,11 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct
     }
   else
     {
-      GNUNET_SCHEDULER_cancel (h->sh->sched, h->sh->write_task);
-      h->sh->write_task = GNUNET_SCHEDULER_NO_TASK;
+      if (h->sh->write_task != GNUNET_SCHEDULER_NO_TASK)
+       {
+         GNUNET_SCHEDULER_cancel (h->sh->sched, h->sh->write_task);
+         h->sh->write_task = GNUNET_SCHEDULER_NO_TASK;
+       }
     }
   h->notify_ready = NULL;
 }