Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix warnings about clobbered variables in gras/console/ping example.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 3 Nov 2011 15:58:15 +0000 (16:58 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 3 Nov 2011 15:59:10 +0000 (16:59 +0100)
examples/gras/console/ping_client.c

index 043fc26..ca0507e 100644 (file)
@@ -9,11 +9,25 @@
 #include "ping.h"
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(Ping);
 
-int client(int argc, char *argv[])
+static gras_socket_t try_gras_socket_client(const char *host, int port)
 {
+  volatile gras_socket_t sock = NULL;
   xbt_ex_t e;
+  TRY {
+    sock = gras_socket_client(host, port);
+  }
+  CATCH(e) {
+    if (e.category != system_error)
+      /* dunno what happened, let the exception go through */
+      RETHROWF("Unable to connect to the server: %s");
+    xbt_ex_free(e);
+  }
+  return sock;
+}
+
+int client(int argc, char *argv[])
+{
   gras_socket_t toserver = NULL;        /* peer */
-  int connected = 0;
 
   gras_socket_t from;
   int ping, pong;
@@ -33,19 +47,8 @@ int client(int argc, char *argv[])
   XBT_INFO("Launch client (server on %s:%d)", host, port);
 
   /* 3. Create a socket to speak to the server */
-  while (!connected) {
-    TRY {
-      toserver = gras_socket_client(host, port);
-      connected = 1;
-    }
-    CATCH(e) {
-      if (e.category != system_error)
-        /* dunno what happened, let the exception go through */
-        RETHROWF("Unable to connect to the server: %s");
-      xbt_ex_free(e);
-      gras_os_sleep(0.05);
-    }
-  }
+  while (!(toserver = try_gras_socket_client(host, port)))
+    gras_os_sleep(0.05);
 
   XBT_INFO("Connected to %s:%d.", host, port);