X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3a1ea70a418f393ca1677074e928c664022295bd..b58b0ba2f6b92efa234677e19dd998346113504d:/examples/c/dht-pastry/dht-pastry.c diff --git a/examples/c/dht-pastry/dht-pastry.c b/examples/c/dht-pastry/dht-pastry.c index af12bf377c..c50c6a4fbb 100644 --- a/examples/c/dht-pastry/dht-pastry.c +++ b/examples/c/dht-pastry/dht-pastry.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2013-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -9,6 +9,7 @@ #include "simgrid/mailbox.h" #include "xbt/dynar.h" +#include "xbt/ex.h" #include "xbt/log.h" #include "xbt/str.h" #include "xbt/sysdep.h" @@ -182,7 +183,7 @@ static state_t node_get_state(const_node_t node) static void print_node_id(const_node_t node) { - XBT_INFO(" Id: %i '%08x' ", node->id, (unsigned)node->id); + XBT_INFO(" Id: %i '%08x'", node->id, (unsigned)node->id); } /* Print the node namespace set */ @@ -264,7 +265,7 @@ static void handle_message(node_t node, pastry_message_t message) } node->namespace_set[NAMESPACE_SIZE / 2 + j] = message->sender_id; node->ready += message->steps + 1; - /* no break */ + /* fallthrough */ case JOIN_REPLY: XBT_DEBUG("Joining Reply"); @@ -424,6 +425,7 @@ static int join(const_node_t node) if (err == SG_ERROR_TIMEOUT) { XBT_DEBUG("Timeout expired when joining ring with node %d", node->known_id); message_free(request); + return 0; } return 1; @@ -445,7 +447,7 @@ static void node(int argc, char* argv[]) double deadline; xbt_assert(argc == 3 || argc == 5, "Wrong number of arguments for this node"); s_node_t node = {0}; - node.id = (int)xbt_str_parse_int(argv[1], "Invalid ID: %s"); + node.id = (int)xbt_str_parse_int(argv[1], "Invalid ID"); node.known_id = -1; node.ready = -1; node.pending_messages = xbt_dynar_new(sizeof(pastry_message_t), NULL); @@ -467,14 +469,14 @@ static void node(int argc, char* argv[]) if (argc == 3) { // first ring XBT_DEBUG("Hey! Let's create the system."); - deadline = xbt_str_parse_double(argv[2], "Invalid deadline: %s"); + deadline = xbt_str_parse_double(argv[2], "Invalid deadline"); node.ready = 0; XBT_DEBUG("Create a new Pastry ring..."); join_success = 1; } else { - node.known_id = (int)xbt_str_parse_int(argv[2], "Invalid known ID: %s"); - double sleep_time = xbt_str_parse_double(argv[3], "Invalid sleep time: %s"); - deadline = xbt_str_parse_double(argv[4], "Invalid deadline: %s"); + node.known_id = (int)xbt_str_parse_int(argv[2], "Invalid known ID"); + double sleep_time = xbt_str_parse_double(argv[3], "Invalid sleep time"); + deadline = xbt_str_parse_double(argv[4], "Invalid deadline"); // sleep before starting XBT_DEBUG("Let's sleep during %f", sleep_time); @@ -513,23 +515,21 @@ int main(int argc, char* argv[]) simgrid_init(&argc, argv); xbt_assert(argc > 2, "Usage: %s [-nb_bits=n] [-timeout=t] platform_file deployment_file\n" - "\tExample: %s ../msg_platform.xml pastry10.xml\n", + "\tExample: %s ../platform.xml pastry10.xml\n", argv[0], argv[0]); char** options = &argv[1]; while (!strncmp(options[0], "-", 1)) { - int length = strlen("-nb_bits="); + size_t length = strlen("-nb_bits="); if (!strncmp(options[0], "-nb_bits=", length) && strlen(options[0]) > length) { - nb_bits = (int)xbt_str_parse_int(options[0] + length, "Invalid nb_bits parameter: %s"); + nb_bits = (int)xbt_str_parse_int(options[0] + length, "Invalid nb_bits parameter"); XBT_DEBUG("Set nb_bits to %d", nb_bits); } else { length = strlen("-timeout="); - if (!strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) { - timeout = (int)xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s"); - XBT_DEBUG("Set timeout to %d", timeout); - } else { - xbt_die("Invalid pastry option '%s'", options[0]); - } + xbt_assert(strncmp(options[0], "-timeout=", length) == 0 && strlen(options[0]) > length, + "Invalid pastry option '%s'", options[0]); + timeout = (int)xbt_str_parse_int(options[0] + length, "Invalid timeout parameter"); + XBT_DEBUG("Set timeout to %d", timeout); } options++; }