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[]) {
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);
37 RETHROW0("Unable to connect to my dady: %s");
39 INFO4("I (%s:%d) have found my dady on %s:%d.",
40 gras_os_myname(),gras_os_myport(),host,port);
43 /* 4. Register the messages. */
44 spawn_register_messages();
49 gras_msg_send(dady, "ping", &ping);
51 gras_socket_close(dady);
52 RETHROW0("Failed to ping my dady: %s");
55 /* 6. Wait for the answer from the server, and deal with issues */
57 gras_msg_wait(6000,"pong", &from,&pong);
59 gras_socket_close(dady);
60 RETHROW0("Dad don't want to speak with me! : %s");
62 INFO2("Pinged dad with %d, he answered with %d; leaving now.", ping, pong);
64 /* 7. Free the allocated resources, and shut GRAS down */
65 gras_socket_close(dady);