From 1f4c6f762971b5398c3d54a7dd0000194ca7edd9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 3 May 2012 13:46:42 +0000 Subject: -towards fixing #2299 --- src/arm/arm_api.c | 40 ++++++++++------------------------------ src/arm/gnunet-service-arm.c | 41 +---------------------------------------- src/arm/mockup-service.c | 30 ------------------------------ 3 files changed, 11 insertions(+), 100 deletions(-) (limited to 'src/arm') diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index f2992b38a..d6b65e872 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c @@ -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, diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index ab9e7f281..663a8e51a 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c @@ -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. diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c index 6f90956db..d9896997b 100644 --- a/src/arm/mockup-service.c +++ b/src/arm/mockup-service.c @@ -29,30 +29,6 @@ #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 (); } -- cgit v1.2.3