Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
First wave of GRAS API breaking: gras_cb_register wants a message name (char*) as...
[simgrid.git] / examples / gras / rpc / rpc.c
index 94fe661..d42614b 100644 (file)
@@ -193,10 +193,11 @@ int client(int argc,char *argv[]) {
     xbt_ex_free(e);
     exception_catching();
   }
-  
-  gras_msg_send(toserver,gras_msgtype_by_name("kill"),NULL);
+
+  INFO2("Ask %s:%d to die",gras_socket_peer_name(toforwarder),gras_socket_peer_port(toforwarder));
   gras_msg_send(toforwarder,gras_msgtype_by_name("kill"),NULL);
-  gras_os_sleep(1); /* give peer a chance to get the message before closing the socket */
+  INFO2("Ask %s:%d to die",gras_socket_peer_name(toserver),gras_socket_peer_port(toserver));
+  gras_msg_send(toserver,gras_msgtype_by_name("kill"),NULL);
 
   /* 11. Cleanup the place before leaving */
   gras_socket_close(toserver);
@@ -217,6 +218,8 @@ typedef struct {
 
 static int forwarder_cb_kill(gras_msg_cb_ctx_t ctx,
                             void             *payload_data) {
+  gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx);
+  INFO2("Asked to die by %s:%d",gras_socket_peer_name(expeditor),gras_socket_peer_port(expeditor));
   forward_data_t fdata=gras_userdata_get();
   fdata->done = 1;
   return 1;
@@ -226,6 +229,7 @@ static int forwarder_cb_forward_ex(gras_msg_cb_ctx_t ctx,
                                   void             *payload_data) {
   forward_data_t fdata=gras_userdata_get();
 
+  INFO0("Forward a request");
   gras_msg_rpccall(fdata->server, 60,
                   gras_msgtype_by_name("raise exception"),NULL,NULL);
   return 1;
@@ -251,10 +255,8 @@ int forwarder (int argc,char *argv[]) {
   fdata->server=gras_socket_client(argv[2],atoi(argv[3]));
 
   register_messages();
-  gras_cb_register(gras_msgtype_by_name("forward exception"),
-                  &forwarder_cb_forward_ex);
-  gras_cb_register(gras_msgtype_by_name("kill"),
-                  &forwarder_cb_kill);
+  gras_cb_register("forward exception", &forwarder_cb_forward_ex);
+  gras_cb_register("kill",              &forwarder_cb_kill);
 
   while (!fdata->done) {
     gras_msg_handle(600.0);
@@ -278,6 +280,9 @@ typedef struct {
 
 static int server_cb_kill(gras_msg_cb_ctx_t ctx,
                          void             *payload_data) {
+  gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx);
+  INFO2("Asked to die by %s:%d",gras_socket_peer_name(expeditor),gras_socket_peer_port(expeditor));
+
   server_data_t sdata=gras_userdata_get();
   sdata->done = 1;
   return 1;
@@ -338,9 +343,9 @@ int server (int argc,char *argv[]) {
 
   /* 4. Register the known messages and register my callback */
   register_messages();
-  gras_cb_register(gras_msgtype_by_name("plain ping"),&server_cb_ping);
-  gras_cb_register(gras_msgtype_by_name("raise exception"),&server_cb_raise_ex);
-  gras_cb_register(gras_msgtype_by_name("kill"),&server_cb_kill);
+  gras_cb_register("plain ping",&server_cb_ping);
+  gras_cb_register("raise exception",&server_cb_raise_ex);
+  gras_cb_register("kill",&server_cb_kill);
 
   INFO1("Listening on port %d ", gras_socket_my_port(mysock));