X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ec16845133f5f1b5262d2d77d8ba22824fa8a446..782ce0488c03c8b13b2267d198a70d6667176f83:/examples/gras/mmrpc/mmrpc_client.c diff --git a/examples/gras/mmrpc/mmrpc_client.c b/examples/gras/mmrpc/mmrpc_client.c index e139989dd5..a4fb89f5ef 100644 --- a/examples/gras/mmrpc/mmrpc_client.c +++ b/examples/gras/mmrpc/mmrpc_client.c @@ -12,16 +12,30 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(MatMult); -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) + 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; xbt_matrix_t request[2], answer; - int i, j; + int i; + _XBT_GNUC_UNUSED int j; const char *host = "127.0.0.1"; int port = 4000; @@ -37,25 +51,14 @@ 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) - RETHROWF("Unable to connect to the server: %s"); - xbt_ex_free(e); - gras_os_sleep(0.05); - } - } - XBT_INFO("Connected to %s:%d.", host, port); - - - /* 4. Register the messages (before use) */ + /* 3. Register the messages (before use) */ mmrpc_register_messages(); + /* 4. Create a socket to speak to the server */ + while (!(toserver = try_gras_socket_client(host, port))) + gras_os_sleep(0.05); + XBT_INFO("Connected to %s:%d.", host, port); + /* 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)); @@ -85,7 +88,7 @@ int client(int argc, char *argv[]) */ for (i = 0; i < MATSIZE; i++) for (j = 0; i < MATSIZE; i++) - xbt_assert4(xbt_matrix_get_as(answer, i, j, double) == + xbt_assert(xbt_matrix_get_as(answer, i, j, double) == xbt_matrix_get_as(request[1], i, j, double), "Answer does not match expectations. Found %f at cell %d,%d instead of %f", xbt_matrix_get_as(answer, i, j, double), i, j,