-towards fixing #2299
authorChristian Grothoff <christian@grothoff.org>
Thu, 3 May 2012 13:46:42 +0000 (13:46 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 3 May 2012 13:46:42 +0000 (13:46 +0000)
src/arm/arm_api.c
src/arm/gnunet-service-arm.c
src/arm/mockup-service.c
src/util/server.c

index f2992b38aba16998e6fa81cb519c2e9027e89602..d6b65e8721ede1f38bf9e0362c18fe3ed9cc09d0 100644 (file)
@@ -87,11 +87,6 @@ struct ShutdownContext
    */
   struct GNUNET_CLIENT_TransmitHandle *th;
 
-  /**
-   * Result of the operation
-   */
-  enum GNUNET_ARM_ProcessStatus confirmed;
-
 };
 
 
@@ -110,37 +105,23 @@ static void
 service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
 {
   struct ShutdownContext *shutdown_ctx = cls;
-  const struct GNUNET_ARM_ResultMessage *rmsg;
 
-  if (msg == NULL)
+  if (NULL != msg)
   {
-    if (shutdown_ctx->cont != NULL)
-    {
-      /* shutdown is now complete, as we waited for the network disconnect... */
-      shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_ARM_PROCESS_DOWN);
-    }
+    /* We just expected a disconnect! Report the error and be done with it... */
+    GNUNET_break (0);
+    shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
     GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
     GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
     GNUNET_free (shutdown_ctx);
     return;
   }
-  if (ntohs (msg->size) ==
-      sizeof (struct GNUNET_ARM_ResultMessage))
-  {
-    rmsg = (const struct GNUNET_ARM_ResultMessage*) msg;
-    shutdown_ctx->confirmed = (enum GNUNET_ARM_ProcessStatus) ntohl (rmsg->status);
-    if (shutdown_ctx->confirmed != GNUNET_ARM_PROCESS_SHUTDOWN)
-    {
-      /* ARM is not shutting down, well, report the error and be done with it... */
-      shutdown_ctx->cont (shutdown_ctx->cont_cls, shutdown_ctx->confirmed);
-      GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
-      GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
-      GNUNET_free (shutdown_ctx);
-      return;
-    }
-  }
-  GNUNET_CLIENT_receive (shutdown_ctx->sock, &service_shutdown_handler,
-                        shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL);
+  if (NULL != shutdown_ctx->cont)
+    /* shutdown is now complete, as we waited for the network disconnect... */
+    shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_ARM_PROCESS_DOWN);    
+  GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+  GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
+  GNUNET_free (shutdown_ctx);
 }
 
 
@@ -225,7 +206,6 @@ arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock,
   shutdown_ctx->cont_cls = cont_cls;
   shutdown_ctx->sock = sock;
   shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
-  shutdown_ctx->confirmed = GNUNET_ARM_PROCESS_COMMUNICATION_ERROR;    
   shutdown_ctx->th = GNUNET_CLIENT_notify_transmit_ready (sock,
                                                          sizeof (struct GNUNET_MessageHeader),
                                                          timeout, GNUNET_NO, &write_shutdown,
index ab9e7f2817632936eddd959acab7628eab86a35b..663a8e51aa717f0bb7d002c16748d7344bab2289 100644 (file)
@@ -1047,41 +1047,6 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 }
 
 
-/**
- * Transmit our shutdown acknowledgement to the client.
- *
- * @param cls the 'struct GNUNET_SERVER_Client'
- * @param size number of bytes available in buf
- * @param buf where to write the message
- * @return number of bytes written
- */
-static size_t
-transmit_shutdown_ack (void *cls, size_t size, void *buf)
-{
-  struct GNUNET_SERVER_Client *client = cls;
-  struct GNUNET_ARM_ResultMessage *msg;
-
-  if (size < sizeof (struct GNUNET_ARM_ResultMessage))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                 _("Failed to transmit shutdown ACK.\n"));
-      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-      return 0;                        /* client disconnected */
-    }
-  /* Make the connection flushing for the purpose of ACK transmitting,
-   * needed on W32 to ensure that the message is even received, harmless
-   * on other platforms... */
-  GNUNET_break (GNUNET_OK == GNUNET_SERVER_client_disable_corking (client));
-  msg = (struct GNUNET_ARM_ResultMessage *) buf;
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_ARM_RESULT);
-  msg->header.size = htons (sizeof (struct GNUNET_ARM_ResultMessage));
-  msg->status = htonl ((uint32_t) GNUNET_ARM_PROCESS_SHUTDOWN);
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
-  GNUNET_SERVER_client_drop (client);
-  return sizeof (struct GNUNET_ARM_ResultMessage);
-}
-
-
 /**
  * Handler for SHUTDOWN message.
  *
@@ -1094,14 +1059,10 @@ handle_shutdown (void *cls, struct GNUNET_SERVER_Client *client,
                 const struct GNUNET_MessageHeader *message)
 {
   GNUNET_SCHEDULER_shutdown ();
-  GNUNET_SERVER_client_keep (client);
-  GNUNET_SERVER_notify_transmit_ready (client,
-                                      sizeof (struct GNUNET_ARM_ResultMessage),
-                                      GNUNET_TIME_UNIT_FOREVER_REL,
-                                      &transmit_shutdown_ack, client);
   GNUNET_SERVER_client_persist_ (client);
 }
 
+
 /**
  * Signal handler called for SIGCHLD.  Triggers the
  * respective handler by writing to the trigger pipe.
index 6f90956db122ced01d3dfd50d292045ebb8e90c6..d9896997be404a98f008f7496b63c8650a93a599 100644 (file)
 #include "gnunet_time_lib.h"
 
 
-static size_t
-transmit_shutdown_ack (void *cls, size_t size, void *buf)
-{
-  struct GNUNET_SERVER_Client *client = cls;
-  struct GNUNET_MessageHeader *msg;
-
-  if (size < sizeof (struct GNUNET_MessageHeader))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                _("Failed to transmit shutdown ACK.\n"));
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return 0;                   /* client disconnected */
-  }
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transmitting shutdown ACK.\n"));
-
-  msg = (struct GNUNET_MessageHeader *) buf;
-  msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN);
-  msg->size = htons (sizeof (struct GNUNET_MessageHeader));
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
-  GNUNET_SERVER_client_drop (client);
-  return sizeof (struct GNUNET_MessageHeader);
-}
-
 /**
  * Handler for SHUTDOWN message.
  *
@@ -64,14 +40,8 @@ static void
 handle_shutdown (void *cls, struct GNUNET_SERVER_Client *client,
                  const struct GNUNET_MessageHeader *message)
 {
-  GNUNET_SERVER_client_keep (client);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               _("Initiating shutdown as requested by client.\n"));
-
-  GNUNET_SERVER_notify_transmit_ready (client,
-                                       sizeof (struct GNUNET_MessageHeader),
-                                       GNUNET_TIME_UNIT_FOREVER_REL,
-                                       &transmit_shutdown_ack, client);
   GNUNET_SERVER_client_persist_ (client);
   GNUNET_SCHEDULER_shutdown ();
 }
index 4c110a134bf81f282513388d18fddfafc86054f6..f92d2f1d09ba7239f2719ec85d69ca53fc0944ee 100644 (file)
@@ -1261,9 +1261,9 @@ GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server,
 void
 GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
 {
+  struct GNUNET_SERVER_Handle *server = client->server;
   struct GNUNET_SERVER_Client *prev;
   struct GNUNET_SERVER_Client *pos;
-  struct GNUNET_SERVER_Handle *server;
   struct NotifyList *n;
   unsigned int rc;
 
@@ -1284,9 +1284,9 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
     GNUNET_CONNECTION_receive_cancel (client->connection);
     client->receive_pending = GNUNET_NO;
   }
-  server = client->server;
   rc = client->reference_count;
-  if (GNUNET_YES != client->shutdown_now)
+  if ( (GNUNET_YES != client->shutdown_now) &&
+       (NULL != server) )
   {
     client->shutdown_now = GNUNET_YES;
     prev = NULL;
@@ -1313,11 +1313,17 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
     }
     for (n = server->disconnect_notify_list_head; NULL != n; n = n->next)
       n->callback (n->callback_cls, client);
+    if (NULL != server->mst_destroy)
+      server->mst_destroy (server->mst_cls, client->mst);
+    else
+      GNUNET_SERVER_mst_destroy (client->mst);
+    client->mst = NULL;
   }
   if (rc > 0)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "RC still positive, not destroying everything.\n");
+    client->server = NULL;
     return;
   }
   if (GNUNET_YES == client->in_process_client_buffer)
@@ -1326,20 +1332,15 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
          "Still processing inputs, not destroying everything.\n");
     return;
   }
-
   if (GNUNET_YES == client->persist)
     GNUNET_CONNECTION_persist_ (client->connection);
   if (NULL != client->th.cth)
     GNUNET_SERVER_notify_transmit_ready_cancel (&client->th);
   GNUNET_CONNECTION_destroy (client->connection);
-
-  if (NULL != server->mst_destroy)
-    server->mst_destroy (server->mst_cls, client->mst);
-  else
-    GNUNET_SERVER_mst_destroy (client->mst);
   GNUNET_free (client);
   /* we might be in soft-shutdown, test if we're done */
-  test_monitor_clients (server);
+  if (NULL != server)
+    test_monitor_clients (server);
 }
 
 
@@ -1377,9 +1378,8 @@ transmit_ready_callback_wrapper (void *cls, size_t size, void *buf)
   client->th.cth = NULL;
   callback = client->th.callback;
   client->th.callback = NULL;
+  client->last_activity = GNUNET_TIME_absolute_get ();
   ret = callback (client->th.callback_cls, size, buf);
-  if (ret > 0)
-    client->last_activity = GNUNET_TIME_absolute_get ();
   return ret;
 }