Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add some peer traces.
[simgrid.git] / examples / gras / rpc / rpc.c
index 42b716f..fe0c62b 100644 (file)
@@ -28,7 +28,7 @@ int forwarder(int argc, char *argv[]);
 int client(int argc, char *argv[]);
 
 #define exception_msg       "Error for the client"
-#define exception_raising() THROW0(unknown_error,42,exception_msg)
+#define exception_raising() THROWF(unknown_error,42,exception_msg)
 
 static void exception_catching(void)
 {
@@ -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) {
-      THROW0(unknown_error, 0, "Didn't got the remote exception!");
+      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);
   }
 }
 
@@ -97,8 +97,8 @@ int client(int argc, char *argv[])
     toserver = gras_socket_client(host, port);
     toforwarder = gras_socket_client(argv[3], atoi(argv[4]));
   }
-  CATCH(e) {
-    RETHROW0("Unable to connect to the server: %s");
+  CATCH_ANONYMOUS {
+    RETHROWF("Unable to connect to the server: %s");
   }
   XBT_INFO("Connected to %s:%d.", host, port);
 
@@ -119,9 +119,9 @@ 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);
-    RETHROW0("Failed to execute a PING rpc on the server: %s");
+    RETHROWF("Failed to execute a PING rpc on the server: %s");
   }
   exception_catching();
 
@@ -138,11 +138,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");
@@ -150,7 +150,7 @@ int client(int argc, char *argv[])
   }
 
   if (!gotit)
-    THROW0(unknown_error, 0, "Didn't got the remote exception!");
+    THROWF(unknown_error, 0, "Didn't got the remote exception!");
 
   XBT_INFO("Called the exception raising RPC");
   exception_catching();
@@ -167,7 +167,7 @@ int client(int argc, char *argv[])
       xbt_ex_free(e);
     }
     if (!gotit) {
-      THROW0(unknown_error, 0, "Didn't got the remote exception!");
+      THROWF(unknown_error, 0, "Didn't got the remote exception!");
     }
   }
   /* doxygen_resume */
@@ -181,19 +181,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) {
-      THROW0(unknown_error, 0, "Didn't got the remote exception!");
+      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();
   }