Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix warnings about clobbered variables in gras/rpc example.
[simgrid.git] / examples / gras / rpc / rpc.c
index da1e116..10e84e0 100644 (file)
@@ -42,17 +42,17 @@ static void exception_catching(void)
     }
     CATCH(e) {
       gotit = 1;
+      xbt_assert(e.category == unknown_error,
+                 "Got wrong category: %d (instead of %d)", e.category,
+                 unknown_error);
+      xbt_assert(e.value == 42, "Got wrong value: %d (!=42)", e.value);
+      xbt_assert(!strncmp(e.msg, exception_msg, strlen(exception_msg)),
+                 "Got wrong message: %s", e.msg);
+      xbt_ex_free(e);
     }
     if (!gotit) {
       THROWF(unknown_error, 0, "Didn't got the remote exception!");
     }
-    xbt_assert2(e.category == unknown_error,
-                "Got wrong category: %d (instead of %d)", e.category,
-                unknown_error);
-    xbt_assert1(e.value == 42, "Got wrong value: %d (!=42)", e.value);
-    xbt_assert1(!strncmp(e.msg, exception_msg, strlen(exception_msg)),
-                "Got wrong message: %s", e.msg);
-    xbt_ex_free(e);
   }
 }
 
@@ -60,6 +60,20 @@ static void exception_catching(void)
  * Client code
  * **********************************************************************/
 
+static void client_create_sockets(gras_socket_t *toserver,
+                                  gras_socket_t *toforwarder,
+                                  const char *srv_host, int srv_port,
+                                  const char *fwd_host, int fwd_port)
+{
+  TRY {
+    exception_catching();
+    *toserver = gras_socket_client(srv_host, srv_port);
+    *toforwarder = gras_socket_client(fwd_host, fwd_port);
+  }
+  CATCH_ANONYMOUS {
+    RETHROWF("Unable to connect to the server: %s");
+  }
+}
 
 int client(int argc, char *argv[])
 {
@@ -92,14 +106,8 @@ int client(int argc, char *argv[])
   gras_os_sleep(2);
 
   /* 4. Create a socket to speak to the server */
-  TRY {
-    exception_catching();
-    toserver = gras_socket_client(host, port);
-    toforwarder = gras_socket_client(argv[3], atoi(argv[4]));
-  }
-  CATCH(e) {
-    RETHROWF("Unable to connect to the server: %s");
-  }
+  client_create_sockets(&toserver, &toforwarder,
+                        host, port, argv[3], atoi(argv[4]));
   XBT_INFO("Connected to %s:%d.", host, port);
 
 
@@ -119,7 +127,7 @@ int client(int argc, char *argv[])
     exception_catching();
     gras_msg_rpccall(toserver, 6000.0, "plain ping", &ping, &pong);
   }
-  CATCH(e) {
+  CATCH_ANONYMOUS {
     gras_socket_close(toserver);
     RETHROWF("Failed to execute a PING rpc on the server: %s");
   }
@@ -138,11 +146,11 @@ int client(int argc, char *argv[])
   }
   CATCH(e) {
     gotit = 1;
-    xbt_assert2(e.category == unknown_error,
+    xbt_assert(e.category == unknown_error,
                 "Got wrong category: %d (instead of %d)",
                 e.category, unknown_error);
-    xbt_assert1(e.value == 42, "Got wrong value: %d (!=42)", e.value);
-    xbt_assert1(!strncmp(e.msg, exception_msg, strlen(exception_msg)),
+    xbt_assert(e.value == 42, "Got wrong value: %d (!=42)", e.value);
+    xbt_assert(!strncmp(e.msg, exception_msg, strlen(exception_msg)),
                 "Got wrong message: %s", e.msg);
     XBT_INFO
         ("Got the expected exception when calling the exception raising RPC");
@@ -181,19 +189,19 @@ int client(int argc, char *argv[])
     }
     CATCH(e) {
       gotit = 1;
+      xbt_assert(e.value == 42, "Got wrong value: %d (!=42)", e.value);
+      xbt_assert(!strncmp(e.msg, exception_msg, strlen(exception_msg)),
+                 "Got wrong message: %s", e.msg);
+      xbt_assert(e.category == unknown_error,
+                 "Got wrong category: %d (instead of %d)",
+                 e.category, unknown_error);
+      XBT_INFO
+        ("Got the expected exception when calling the exception raising RPC");
+      xbt_ex_free(e);
     }
     if (!gotit) {
       THROWF(unknown_error, 0, "Didn't got the remote exception!");
     }
-    xbt_assert1(e.value == 42, "Got wrong value: %d (!=42)", e.value);
-    xbt_assert1(!strncmp(e.msg, exception_msg, strlen(exception_msg)),
-                "Got wrong message: %s", e.msg);
-    xbt_assert2(e.category == unknown_error,
-                "Got wrong category: %d (instead of %d)",
-                e.category, unknown_error);
-    XBT_INFO
-        ("Got the expected exception when calling the exception raising RPC");
-    xbt_ex_free(e);
     exception_catching();
   }