X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f783ed4680c6862a1b7543237e89d1221334bae0..2d16ebcee6bde01575b4cd88a853e1ac1c2532bf:/examples/gras/console/ping_client.c diff --git a/examples/gras/console/ping_client.c b/examples/gras/console/ping_client.c index 043fc260bf..d0af52500e 100644 --- a/examples/gras/console/ping_client.c +++ b/examples/gras/console/ping_client.c @@ -9,13 +9,27 @@ #include "ping.h" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(Ping); -int client(int argc, char *argv[]) +static xbt_socket_t try_gras_socket_client(const char *host, int port) { + volatile xbt_socket_t sock = NULL; xbt_ex_t e; - gras_socket_t toserver = NULL; /* peer */ - int connected = 0; + 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; +} - gras_socket_t from; +int client(int argc, char *argv[]) +{ + xbt_socket_t toserver = NULL; /* peer */ + + xbt_socket_t from; int ping, pong; const char *host = "127.0.0.1"; @@ -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); @@ -55,7 +58,7 @@ int client(int argc, char *argv[]) /* 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)); + xbt_socket_peer_name(toserver), xbt_socket_peer_port(toserver)); /* 6. Prepare and send the ping message to the server */ ping = 1234; @@ -68,7 +71,7 @@ int client(int argc, char *argv[]) } XBT_INFO(">>>>>>>> Message PING(%d) sent to %s:%d <<<<<<<<", ping, - gras_socket_peer_name(toserver), gras_socket_peer_port(toserver)); + xbt_socket_peer_name(toserver), xbt_socket_peer_port(toserver)); /* 7. Wait for the answer from the server, and deal with issues */ TRY { @@ -81,7 +84,7 @@ int client(int argc, char *argv[]) /* 8. Keep the user informed of what's going on, again */ XBT_INFO(">>>>>>>> Got PONG(%d) from %s:%d <<<<<<<<", - pong, gras_socket_peer_name(from), gras_socket_peer_port(from)); + pong, xbt_socket_peer_name(from), xbt_socket_peer_port(from)); /* 9. Free the allocated resources, and shut GRAS down */ gras_socket_close(toserver);