Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Stop using the logs when they are not ready anymore
[simgrid.git] / examples / gras / rpc / rpc.c
index 66c1b2e..3248639 100644 (file)
@@ -67,13 +67,14 @@ int client(int argc,char *argv[]) {
   gras_socket_t toserver=NULL; /* peer */
   gras_socket_t toforwarder=NULL; /* peer */
 
-  memset(&e,0,sizeof(xbt_ex_t));
-
   int ping, pong, i;
   volatile int gotit=0;
 
+
   const char *host = "127.0.0.1";
-        int   port = 4000;
+               int   port = 4000;
+
+  memset(&e,0,sizeof(xbt_ex_t));
 
   /* 1. Init the GRAS's infrastructure */
   gras_init(&argc, argv);
@@ -115,8 +116,7 @@ int client(int argc,char *argv[]) {
   ping = 1234;
   TRY {
     exception_catching();
-    gras_msg_rpccall(toserver, 6000.0,
-                    gras_msgtype_by_name("plain ping"), &ping, &pong);
+    gras_msg_rpccall(toserver, 6000.0, "plain ping", &ping, &pong);
   } CATCH(e) {
     gras_socket_close(toserver);
     RETHROW0("Failed to execute a PING rpc on the server: %s");
@@ -132,8 +132,7 @@ int client(int argc,char *argv[]) {
   /* 9. Call a RPC which raises an exception (to test exception propagation) */
   INFO0("Call the exception raising RPC");
   TRY {
-    gras_msg_rpccall(toserver, 6000.0,
-                    gras_msgtype_by_name("raise exception"), NULL, NULL);
+    gras_msg_rpccall(toserver, 6000.0, "raise exception", NULL, NULL);
   } CATCH(e) {
     gotit = 1; 
     xbt_assert2(e.category == unknown_error, 
@@ -158,8 +157,7 @@ int client(int argc,char *argv[]) {
        
      INFO1("Call the exception raising RPC (i=%d)",i);
      TRY {
-       gras_msg_rpccall(toserver, 6000.0,
-                        gras_msgtype_by_name("raise exception"), NULL, NULL);
+       gras_msg_rpccall(toserver, 6000.0, "raise exception", NULL, NULL);
      } CATCH(e) {
        gotit = 1;
        xbt_ex_free(e);
@@ -174,8 +172,7 @@ int client(int argc,char *argv[]) {
   for (i=0;i<5;i++) {
     INFO1("Call the exception raising RPC on the forwarder (i=%d)",i);
     TRY {
-      gras_msg_rpccall(toforwarder, 6000.0,
-                      gras_msgtype_by_name("forward exception"), NULL, NULL);
+      gras_msg_rpccall(toforwarder, 6000.0, "forward exception", NULL, NULL);
     } CATCH(e) {
       gotit = 1;
     }
@@ -195,15 +192,15 @@ int client(int argc,char *argv[]) {
   }
 
   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_msg_send(toforwarder,"kill",NULL);
   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);
+  gras_msg_send(toserver,"kill",NULL);
 
   /* 11. Cleanup the place before leaving */
   gras_socket_close(toserver);
   gras_socket_close(toforwarder);
-  gras_exit();
   INFO0("Done.");
+  gras_exit();
   return 0;
 } /* end_of_client */
 
@@ -217,12 +214,13 @@ typedef struct {
 } s_forward_data_t, *forward_data_t;
 
 static int forwarder_cb_kill(gras_msg_cb_ctx_t ctx,
-                            void             *payload_data) {
+                                void             *payload_data) {
+  forward_data_t fdata;
   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=gras_userdata_get();
   fdata->done = 1;
-  return 1;
+  return 0;
 }
 
 static int forwarder_cb_forward_ex(gras_msg_cb_ctx_t ctx,
@@ -230,9 +228,8 @@ static int forwarder_cb_forward_ex(gras_msg_cb_ctx_t ctx,
   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;
+  gras_msg_rpccall(fdata->server, 60, "raise exception",NULL,NULL);
+  return 0;
 }
 
 int forwarder (int argc,char *argv[]) {
@@ -255,10 +252,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);
@@ -267,8 +262,8 @@ int forwarder (int argc,char *argv[]) {
   gras_socket_close(mysock);
   gras_socket_close(fdata->server);
   free(fdata);
-  gras_exit();
   INFO0("Done.");
+  gras_exit();
   return 0;
 }
 
@@ -283,17 +278,19 @@ 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);
+  server_data_t sdata;
+
   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=gras_userdata_get();
   sdata->done = 1;
-  return 1;
+  return 0;
 }
 
 static int server_cb_raise_ex(gras_msg_cb_ctx_t ctx,
                              void             *payload_data) {
   exception_raising();
-  return 1;
+  return 0;
 }
 
 static int server_cb_ping(gras_msg_cb_ctx_t ctx,
@@ -318,7 +315,7 @@ static int server_cb_ping(gras_msg_cb_ctx_t ctx,
   /* 6. Cleanups, if any */
 
   /* 7. Tell GRAS that we consummed this message */
-  return 1;
+  return 0;
 } /* end_of_server_cb_ping */
 
 
@@ -345,9 +342,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));
 
@@ -385,9 +382,9 @@ int server (int argc,char *argv[]) {
   /* 8. Free the allocated resources, and shut GRAS down */
   free(sdata);
   gras_socket_close(mysock);
+  INFO0("Done.");
   gras_exit();
    
-  INFO0("Done.");
   return 0;
 } /* end_of_server */