int remaining_loop; /* number of loops to do until done */
int create; /* whether I have to create the token */
gras_socket_t tosuccessor; /* how to connect to the successor on ring */
+ double start_time; /* to measure the elapsed time. Only used by the
+ node that creates the token */
} node_data_t;
/* 8. Repport the hop number to the user at the end */
if (globals->remaining_loop == -1 && globals->create) {
+ double elapsed = gras_os_time() - globals->start_time;
INFO1("Shut down the token-ring. There was %d hops.",msg);
+ VERB1("Elapsed time: %g", elapsed);
}
/* 9. Tell GRAS that we consummed this message */
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);
if (globals->create) {
int token = 0;
-
+
+ globals->start_time = gras_os_time();
+
globals->remaining_loop = NBLOOPS - 1;
INFO3("Create the token (with value %d) and send it to %s:%d",
/* 8. Wait up to 10 seconds for an incomming message to handle */
while (globals->remaining_loop > (globals->create ? -1 : 0)) {
- gras_msg_handle(10.0);
+ gras_msg_handle(-1);
DEBUG1("looping (remaining_loop=%d)", globals->remaining_loop);
}