3 /* spawn - demo of the gras_agent_spawn function */
5 /* Copyright (c) 2007 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
11 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(Spawn);
13 int child(int argc, char *argv[])
16 gras_socket_t dady = NULL; /* peer */
21 const char *host = gras_os_myname();
24 /* 1. Init the GRAS's infrastructure */
25 gras_init(&argc, argv);
27 /* 2. Get the server's address. The command line override defaults when specified */
32 gras_socket_server_range(4000, 5000, 0, 0);
34 /* 3. Connect back to my father */
36 dady = gras_socket_client(host, port);
39 RETHROW0("Unable to connect to my dady: %s");
41 INFO4("I (%s:%d) have found my dady on %s:%d.",
42 gras_os_myname(), gras_os_myport(), host, port);
45 /* 4. Register the messages. */
46 spawn_register_messages();
51 gras_msg_send(dady, "ping", &ping);
54 gras_socket_close(dady);
55 RETHROW0("Failed to ping my dady: %s");
58 /* 6. Wait for the answer from the server, and deal with issues */
60 gras_msg_wait(6000, "pong", &from, &pong);
63 gras_socket_close(dady);
64 RETHROW0("Dad don't want to speak with me! : %s");
66 INFO2("Pinged dad with %d, he answered with %d; leaving now.", ping, pong);
68 /* 7. Free the allocated resources, and shut GRAS down */
69 gras_socket_close(dady);