- struct ShutdownContext *shutdown_ctx = cls;
-
- if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES))
- {
- /* Means the other side closed the connection and never confirmed a shutdown */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Service handle shutdown before ACK!\n");
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
- GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- }
- else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Service shutdown complete.\n");
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO);
-
- GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- }
- else
- {
- GNUNET_assert(ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader));
-
- switch (ntohs(msg->type))
- {
- case GNUNET_MESSAGE_TYPE_SHUTDOWN_ACK:
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Received confirmation for service shutdown.\n");
- shutdown_ctx->confirmed = GNUNET_YES;
- GNUNET_CLIENT_receive (shutdown_ctx->sock,
- &service_shutdown_handler,
- shutdown_ctx,
- GNUNET_TIME_UNIT_FOREVER_REL);
- break;
- case GNUNET_MESSAGE_TYPE_SHUTDOWN_REFUSE:
- default: /* Fall through */
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Service shutdown refused!\n");
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES);
-
- GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- break;
- }
- }
-}
-
-/**
- * Shutting down took too long, cancel receive and return error.
- *
- * @param cls closure
- * @param tc context information (why was this task triggered now)
- */
-void service_shutdown_cancel (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
-{
- struct ShutdownContext *shutdown_ctx = cls;
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "service_shutdown_cancel called!\n");
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
+ struct ClientState *cstate = impl_state;
+
+ if (GNUNET_SYSERR == cstate->in_destroy)
+ {
+ /* defer destruction */
+ cstate->in_destroy = GNUNET_YES;
+ cstate->mq = NULL;
+ return;
+ }
+ if (NULL != cstate->dns_active)
+ GNUNET_RESOLVER_request_cancel (cstate->dns_active);
+ if (NULL != cstate->send_task)
+ GNUNET_SCHEDULER_cancel (cstate->send_task);
+ if (NULL != cstate->recv_task)
+ GNUNET_SCHEDULER_cancel (cstate->recv_task);
+ if (NULL != cstate->retry_task)
+ GNUNET_SCHEDULER_cancel (cstate->retry_task);
+ if (NULL != cstate->sock)
+ GNUNET_NETWORK_socket_close (cstate->sock);
+ cancel_aps (cstate);
+ GNUNET_free (cstate->service_name);
+ GNUNET_free_non_null (cstate->hostname);
+ GNUNET_MST_destroy (cstate->mst);
+ GNUNET_free (cstate);