X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8a6bb3ec35a4d3ebc36ef08cc6dcdfcec51de572..0d3559e1b91e1976a6f2558f9889cf6f1066a1ab:/examples/gras/mutual_exclusion/simple_token/simple_token.c diff --git a/examples/gras/mutual_exclusion/simple_token/simple_token.c b/examples/gras/mutual_exclusion/simple_token/simple_token.c index 0ad688f461..873dc0b0b5 100644 --- a/examples/gras/mutual_exclusion/simple_token/simple_token.c +++ b/examples/gras/mutual_exclusion/simple_token/simple_token.c @@ -72,8 +72,7 @@ static int node_cb_stoken_handler(gras_msg_cb_ctx_t ctx, void *payload) { /* 5. Send the token as payload of a stoken message to the successor */ TRY { - gras_msg_send(globals->tosuccessor, - gras_msgtype_by_name("stoken"), &msg); + gras_msg_send(globals->tosuccessor, "stoken", &msg); /* 6. Deal with errors */ } CATCH(e) { @@ -96,7 +95,7 @@ static int node_cb_stoken_handler(gras_msg_cb_ctx_t ctx, void *payload) { } /* 9. Tell GRAS that we consummed this message */ - return 1; + return 0; } /* end_of_node_cb_stoken_handler */ int node (int argc,char *argv[]) { @@ -130,27 +129,27 @@ int node (int argc,char *argv[]) { globals->tosuccessor = NULL; if (!gras_os_getpid() % 100) - INFO4("Launch node %ld (successor on %s:%d; listening on %d)", + INFO4("Launch node %d (successor on %s:%d; listening on %d)", gras_os_getpid(), host,peerport, myport); - /* 4. Create my master socket for listening */ + /* 4. Register the known messages. */ + gras_msgtype_declare("stoken", gras_datadesc_by_name("int")); + + /* 5. Create my master socket for listening */ globals->sock = gras_socket_server(myport); gras_os_sleep(1.0); /* Make sure all server sockets are created */ - - /* 5. Create socket to the successor on the ring */ + + /* 6. Create socket to the successor on the ring */ DEBUG2("Connect to my successor on %s:%d",host,peerport); globals->tosuccessor = gras_socket_client(host,peerport); - /* 6. Register the known messages. */ - gras_msgtype_declare("stoken", gras_datadesc_by_name("int")); - /* 7. Register my callback */ gras_cb_register("stoken",&node_cb_stoken_handler); /* 8. One node has to create the token at startup. It's specified by a command line argument */ - if (argc >= 5 && !strncmp("--create-token", argv[4],strlen(argv[4]))) + if (argc >= 5 && !strncmp("--create-token", argv[4],strlen("--create-token"))) globals->create=1; if (globals->create) { @@ -162,8 +161,7 @@ int node (int argc,char *argv[]) { token, host, peerport); TRY { - gras_msg_send(globals->tosuccessor, - gras_msgtype_by_name("stoken"), &token); + gras_msg_send(globals->tosuccessor, "stoken", &token); } CATCH(e) { RETHROW0("Unable to send the freshly created token: %s"); }