1 /* spawn - demo of the gras_agent_spawn function */
3 /* Copyright (c) 2007, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
10 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(Spawn);
12 int child(int argc, char *argv[])
15 gras_socket_t dady = NULL; /* peer */
20 const char *host = gras_os_myname();
23 /* 1. Init the GRAS's infrastructure */
24 gras_init(&argc, argv);
26 /* 2. Get the server's address. The command line override defaults when specified */
31 gras_socket_server_range(4000, 5000, 0, 0);
33 /* 3. Connect back to my father */
35 dady = gras_socket_client(host, port);
38 RETHROW0("Unable to connect to my dady: %s");
40 INFO4("I (%s:%d) have found my dady on %s:%d.",
41 gras_os_myname(), gras_os_myport(), host, port);
44 /* 4. Register the messages. */
45 spawn_register_messages();
50 gras_msg_send(dady, "ping", &ping);
53 gras_socket_close(dady);
54 RETHROW0("Failed to ping my dady: %s");
57 /* 6. Wait for the answer from the server, and deal with issues */
59 gras_msg_wait(6000, "pong", &from, &pong);
62 gras_socket_close(dady);
63 RETHROW0("Dad don't want to speak with me! : %s");
65 INFO2("Pinged dad with %d, he answered with %d; leaving now.", ping,
68 /* 7. Free the allocated resources, and shut GRAS down */
69 gras_socket_close(dady);