Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simix does not display event occuring at the same timestamp than the old version...
[simgrid.git] / examples / gras / rpc / rpc.c
index d42614b..14e27e4 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);
@@ -108,15 +109,14 @@ int client(int argc,char *argv[]) {
   register_messages();
 
   /* 6. Keep the user informed of what's going on */
-  INFO2("Connected to server which is on %s:%d ", 
+  INFO2("Connected to server which is on %s:%d",
        gras_socket_peer_name(toserver),gras_socket_peer_port(toserver));
 
   /* 7. Prepare and send the ping message to the server */
   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");
@@ -124,7 +124,7 @@ int client(int argc,char *argv[]) {
   exception_catching();
 
   /* 8. Keep the user informed of what's going on, again */
-  INFO4("The answer to PING(%d) on %s:%d is PONG(%d)  ", 
+  INFO4("The answer to PING(%d) on %s:%d is PONG(%d)",
        ping, 
        gras_socket_peer_name(toserver),gras_socket_peer_port(toserver),
        pong);
@@ -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[]) {
@@ -265,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;
 }
 
@@ -281,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,
@@ -302,7 +301,7 @@ static int server_cb_ping(gras_msg_cb_ctx_t ctx,
   gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx);
    
   /* 2. Log which client connected */
-  INFO3("Got message PING(%d) from %s:%d ", 
+  INFO3("Got message PING(%d) from %s:%d",
        msg, 
        gras_socket_peer_name(expeditor), gras_socket_peer_port(expeditor));
   
@@ -316,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 */
 
 
@@ -347,7 +346,7 @@ int server (int argc,char *argv[]) {
   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));
+  INFO1("Listening on port %d", gras_socket_my_port(mysock));
 
   /* 5. Wait for the ping incomming messages */
   
@@ -383,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 */