asserts
[oweals/gnunet.git] / src / util / server_nc.c
index e2c74a7e9254fae143085c3217a8568885d7573b..88de62c63f4a20a1b1cb9112ca1825b1969912f1 100644 (file)
@@ -131,6 +131,12 @@ struct GNUNET_SERVER_NotificationContext
 };
 
 
+/**
+ * Client has disconnected, clean up.
+ *
+ * @param cls our 'struct GNUNET_SERVER_NotificationContext *'
+ * @param client handle of client that disconnected
+ */
 static void
 handle_client_disconnect (void *cls,
                          struct GNUNET_SERVER_Client *client)
@@ -140,6 +146,11 @@ handle_client_disconnect (void *cls,
   struct ClientList *prev;
   struct PendingMessageList *pml;
 
+  if (client == NULL)
+    {
+      nc->server = NULL;
+      return;
+    }
   prev = NULL;
   pos = nc->clients;
   while (NULL != pos)
@@ -161,6 +172,11 @@ handle_client_disconnect (void *cls,
       GNUNET_free (pml);
     }
   GNUNET_SERVER_client_drop (client);
+  if (pos->th != NULL)
+    {
+      GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
+      pos->th = NULL;
+    }
   GNUNET_free (pos);
 }
 
@@ -204,8 +220,8 @@ GNUNET_SERVER_notification_context_destroy (struct GNUNET_SERVER_NotificationCon
   while (NULL != (pos = nc->clients))
     {
       nc->clients = pos->next;
-      GNUNET_SERVER_receive_done (pos->client, GNUNET_NO);
       GNUNET_SERVER_client_drop (pos->client); 
+      GNUNET_SERVER_receive_done (pos->client, GNUNET_NO);
       while (NULL != (pml = pos->pending_head))
        {
          pos->pending_head = pml->next;
@@ -213,9 +229,10 @@ GNUNET_SERVER_notification_context_destroy (struct GNUNET_SERVER_NotificationCon
        }
       GNUNET_free (pos);
     }
-  GNUNET_SERVER_disconnect_notify_cancel (nc->server,
-                                         &handle_client_disconnect,
-                                         nc);
+  if (nc->server != NULL)
+    GNUNET_SERVER_disconnect_notify_cancel (nc->server,
+                                           &handle_client_disconnect,
+                                           nc);
   GNUNET_free (nc);
 }