Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix race condition with gras-mmrpc test.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Fri, 14 Oct 2011 11:38:25 +0000 (13:38 +0200)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 20 Oct 2011 09:48:59 +0000 (11:48 +0200)
Register messages before opening the sockets, to avoid to receive
unknown messages.

examples/gras/mmrpc/mmrpc_client.c
examples/gras/mmrpc/mmrpc_server.c

index ec62e36..4719e1d 100644 (file)
@@ -37,7 +37,10 @@ int client(int argc, char *argv[])
 
   XBT_INFO("Launch client (server on %s:%d)", host, port);
 
 
   XBT_INFO("Launch client (server on %s:%d)", host, port);
 
-  /* 3. Create a socket to speak to the server */
+  /* 3. Register the messages (before use) */
+  mmrpc_register_messages();
+
+  /* 4. Create a socket to speak to the server */
   while (!connected) {
     TRY {
       toserver = gras_socket_client(host, port);
   while (!connected) {
     TRY {
       toserver = gras_socket_client(host, port);
@@ -52,10 +55,6 @@ int client(int argc, char *argv[])
   }
   XBT_INFO("Connected to %s:%d.", host, port);
 
   }
   XBT_INFO("Connected to %s:%d.", host, port);
 
-
-  /* 4. Register the messages (before use) */
-  mmrpc_register_messages();
-
   /* 5. Keep the user informed of what's going on */
   XBT_INFO(">>>>>>>> Connected to server which is on %s:%d <<<<<<<<",
         gras_socket_peer_name(toserver), gras_socket_peer_port(toserver));
   /* 5. Keep the user informed of what's going on */
   XBT_INFO(">>>>>>>> Connected to server which is on %s:%d <<<<<<<<",
         gras_socket_peer_name(toserver), gras_socket_peer_port(toserver));
index 7784d04..bcaf5f1 100644 (file)
@@ -51,7 +51,13 @@ int server(int argc, char *argv[])
     port = atoi(argv[1]);
   }
 
     port = atoi(argv[1]);
   }
 
-  /* 3. Create my master socket */
+  /* 3. Register the known messages and payloads. */
+  mmrpc_register_messages();
+
+  /* 4. Register my callback */
+  gras_cb_register("request", &server_cb_request_handler);
+
+  /* 5. Create my master socket */
   XBT_INFO("Launch server (port=%d)", port);
   TRY {
     sock = gras_socket_server(port);
   XBT_INFO("Launch server (port=%d)", port);
   TRY {
     sock = gras_socket_server(port);
@@ -60,12 +66,6 @@ int server(int argc, char *argv[])
     RETHROWF("Unable to establish a server socket: %s");
   }
 
     RETHROWF("Unable to establish a server socket: %s");
   }
 
-  /* 4. Register the known messages and payloads. */
-  mmrpc_register_messages();
-
-  /* 5. Register my callback */
-  gras_cb_register("request", &server_cb_request_handler);
-
   /* 6. Wait up to 10 minutes for an incomming message to handle */
   gras_msg_handle(600.0);
 
   /* 6. Wait up to 10 minutes for an incomming message to handle */
   gras_msg_handle(600.0);