static void forward_get_suc(get_suc_t msg, char host[1024], int port)
{
gras_socket_t temp_sock = NULL;
- xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
- //INFO2("Transmiting message to %s:%d",host,port);
+ //XBT_INFO("Transmiting message to %s:%d",host,port);
TRY {
temp_sock = gras_socket_client(host, port);
- } CATCH(e) {
- RETHROW0("Unable to connect!: %s");
+ }
+ CATCH_ANONYMOUS {
+ RETHROWF("Unable to connect!: %s");
}
TRY {
gras_msg_send(temp_sock, "can_get_suc", &msg);
- } CATCH(e) {
- RETHROW0("Unable to send!: %s");
}
- INFO3("Forwarding a get_successor message to %s for (%d;%d)", host,
+ CATCH_ANONYMOUS {
+ RETHROWF("Unable to send!: %s");
+ }
+ XBT_INFO("Forwarding a get_successor message to %s for (%d;%d)", host,
msg.xId, msg.yId);
gras_socket_close(temp_sock);
}
xbt_ex_t e; // the error variable used in TRY.. CATCH tokens.
node_data_t *globals = (node_data_t *) gras_userdata_get();
gras_socket_t temp_sock = NULL;
- INFO3("Received a get_successor message from %s for (%d;%d)",
+ XBT_INFO("Received a get_successor message from %s for (%d;%d)",
gras_socket_peer_name(expeditor), incoming->xId, incoming->yId);
- //INFO4("My area is [%d;%d;%d;%d]",globals->x1,globals->x2,globals->y1,globals->y2);
+ //XBT_INFO("My area is [%d;%d;%d;%d]",globals->x1,globals->x2,globals->y1,globals->y2);
if (incoming->xId < globals->x1) // test if the message must be forwarded to a neighbour.
forward_get_suc(*incoming, globals->west_host, globals->west_port);
else if (incoming->xId > globals->x2)
else { // if the message must not be forwarded, then the area is splitted in half and one half is assignated to the new node.
rep_suc_t outgoing;
int validate = 0;
- INFO4
+ XBT_INFO
("Spliting my area between me (%d;%d) and the inserting node (%d;%d)!",
globals->xId, globals->yId, incoming->xId, incoming->yId);
if ((globals->x2 - globals->x1) > (globals->y2 - globals->y1)) { // the height of the area is smaller than its width.
}
}
if (validate == 1) { // the area for the new node has been defined, then send theses informations to the new node.
- INFO2("Sending environment informations to node %s:%d",
+ XBT_INFO("Sending environment informations to node %s:%d",
incoming->host, incoming->port);
TRY {
temp_sock = gras_socket_client(incoming->host, incoming->port);
}
- CATCH(e) {
- RETHROW0
+ CATCH_ANONYMOUS {
+ RETHROWF
("Unable to connect to the node wich has requested for an area!: %s");
}
TRY {
gras_msg_send(temp_sock, "can_rep_suc", &outgoing);
- INFO0("Environment informations sent!");
+ XBT_INFO("Environment informations sent!");
}
- CATCH(e) {
- RETHROW2("%s:Timeout sending environment informations to %s: %s",
+ CATCH_ANONYMOUS {
+ RETHROWF("%s:Timeout sending environment informations to %s: %s",
globals->host, gras_socket_peer_name(expeditor));
}
gras_socket_close(temp_sock);
} else // we have a problem!
- INFO0("An error occurded!!!!!!!!!!!!!");
+ XBT_INFO("An error occurded!!!!!!!!!!!!!");
}
gras_socket_close(expeditor); // spare
gras_msg_handle(10000.0); // wait a bit in case of someone want to ask me for something.
}
CATCH(e) {
- INFO4("My area is [%d;%d;%d;%d]", globals->x1, globals->x2,
+ XBT_INFO("My area is [%d;%d;%d;%d]", globals->x1, globals->x2,
globals->y1, globals->y2);
- //INFO0("Closing node, all has been done!");
+ //XBT_INFO("Closing node, all has been done!");
+ xbt_ex_free(e);
}
return 0;
}
get_suc_t get_suc_msg; // building the "get_suc" message.
gras_socket_t temp_sock2 = NULL;
- INFO0("Starting");
+ XBT_INFO("Starting");
/* 1. Init the GRAS infrastructure and declare my globals */
gras_init(&argc, argv);
globals->version = 0; // node version (used for fun)
/* 2. Inserting the Node */
- INFO2("Inserting node %s:%d", globals->host, globals->port);
+ XBT_INFO("Inserting node %s:%d", globals->host, globals->port);
if (argc == 4) { // the node is a server, then he has the whole area.
globals->x1 = 0;
globals->x2 = 1000;
globals->y1 = 0;
globals->y2 = 1000;
} else { // asking for an area.
- INFO1("Contacting %s so as to request for an area", argv[4]);
+ XBT_INFO("Contacting %s so as to request for an area", argv[4]);
TRY {
temp_sock = gras_socket_client(argv[4], atoi(argv[5]));
}
- CATCH(e) {
- RETHROW0("Unable to connect known host to request for an area!: %s");
+ CATCH_ANONYMOUS {
+ RETHROWF("Unable to connect known host to request for an area!: %s");
}
TRY { // asking.
gras_msg_send(temp_sock, "can_get_suc", &get_suc_msg);
}
- CATCH(e) {
+ CATCH_ANONYMOUS {
gras_socket_close(temp_sock);
- RETHROW0("Unable to contact known host to get an area!: %s");
+ RETHROWF("Unable to contact known host to get an area!: %s");
}
gras_socket_close(temp_sock);
TRY { // waiting for a reply.
- INFO0("Waiting for reply!");
+ XBT_INFO("Waiting for reply!");
gras_msg_wait(6000, "can_rep_suc", &temp_sock2, &rep_suc_msg);
}
- CATCH(e) {
- RETHROW1("%s: Error waiting for an area:%s", globals->host);
+ CATCH_ANONYMOUS {
+ RETHROWF("%s: Error waiting for an area:%s", globals->host);
}
// retreiving the data of the response.
gras_socket_close(temp_sock); // spare
}
- INFO2("Node %s:%d inserted", globals->host, globals->port);
+ XBT_INFO("Node %s:%d inserted", globals->host, globals->port);
// associating messages to handlers.
register_messages();
gras_msg_handle(10000.0); // waiting.. in case of someone has something to say.
}
CATCH(e) {
- INFO4("My area is [%d;%d;%d;%d]", globals->x1, globals->x2,
+ XBT_INFO("My area is [%d;%d;%d;%d]", globals->x1, globals->x2,
globals->y1, globals->y2);
- //INFO0("Closing node, all has been done!");
+ //XBT_INFO("Closing node, all has been done!");
+ xbt_ex_free(e);
}
gras_socket_close(globals->sock); // spare.