From 64c3572367a0944cbb51a4886ffcb2dc081ab979 Mon Sep 17 00:00:00 2001 From: mquinson Date: Sat, 15 Jul 2006 17:34:09 +0000 Subject: [PATCH] Chapter 3 git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2579 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- doc/gtut-files/.cvsignore | 25 ++++++++++++++++++++++ doc/gtut-files/1-bones.output | 4 ++-- doc/gtut-files/3-args.c | 39 +++++++++++++++++++++++++++++++++++ doc/gtut-files/3-args.xml | 12 +++++++++++ doc/gtut-files/Makefile | 27 ++++++++++++++++++++---- 5 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 doc/gtut-files/.cvsignore create mode 100644 doc/gtut-files/3-args.c create mode 100644 doc/gtut-files/3-args.xml diff --git a/doc/gtut-files/.cvsignore b/doc/gtut-files/.cvsignore new file mode 100644 index 0000000000..8e4bb79588 --- /dev/null +++ b/doc/gtut-files/.cvsignore @@ -0,0 +1,25 @@ +1-bones.mk +1-bones.trace +1-bones_client +1-bones_server +1-bones_simulator +_1-bones_client.c +_1-bones_server.c +_1-bones_simulator.c +_2-simple_client.c +_2-simple_server.c +_2-simple_simulator.c +2-simple.mk +2-simple.trace +2-simple_client +2-simple_server +2-simple_simulator +3-args.mk +3-args.output +3-args.trace +3-args_client +3-args_server +3-args_simulator +_3-args_client.c +_3-args_server.c +_3-args_simulator.c diff --git a/doc/gtut-files/1-bones.output b/doc/gtut-files/1-bones.output index 2a079b15e4..014775c1e5 100644 --- a/doc/gtut-files/1-bones.output +++ b/doc/gtut-files/1-bones.output @@ -1,7 +1,7 @@ $ ./test_client -[blaise:client:(27306) 0.000004] gras/gras.c:79: [gras/INFO] Exiting GRAS +[blaise:client:(22033) 0.000005] gras/gras.c:79: [gras/INFO] Exiting GRAS $ ./test_server -[blaise:server:(27309) 0.000005] gras/gras.c:79: [gras/INFO] Exiting GRAS +[blaise:server:(22036) 0.000004] gras/gras.c:79: [gras/INFO] Exiting GRAS $ ./test_simulator platform.xml test.xml [Jacquelin:server:(1) 0.000000] gras/gras.c:79: [gras/INFO] Exiting GRAS [Boivin:client:(2) 0.000000] gras/gras.c:79: [gras/INFO] Exiting GRAS diff --git a/doc/gtut-files/3-args.c b/doc/gtut-files/3-args.c new file mode 100644 index 0000000000..e4875aca0e --- /dev/null +++ b/doc/gtut-files/3-args.c @@ -0,0 +1,39 @@ +#include + +int server(int argc, char *argv[]) { + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toclient; /* socket used to write to the client */ + + gras_init(&argc,argv); + + gras_msgtype_declare("hello", NULL); + mysock = gras_socket_server(atoi(argv[1])); + + gras_msg_wait(60, gras_msgtype_by_name("hello"), &toclient, NULL /* no payload */); + + fprintf(stderr,"Cool, we received the message from %s:%d.\n", + gras_socket_peer_name(toclient), gras_socket_peer_port(toclient)); + + gras_exit(); + return 0; +} +int client(int argc, char *argv[]) { + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toserver; /* socket used to write to the server */ + + gras_init(&argc,argv); + + gras_msgtype_declare("hello", NULL); + mysock = gras_socket_server_range(1024, 10000, 0, 0); + + fprintf(stderr,"Client ready; listening on %d\n", gras_socket_my_port(mysock)); + + gras_os_sleep(1.5); /* sleep 1 second and half */ + toserver = gras_socket_client(argv[1], atoi(argv[2])); + + gras_msg_send(toserver,gras_msgtype_by_name("hello"), NULL); + fprintf(stderr,"That's it, we sent the data to the server on %s\n", gras_socket_peer_name(toserver)); + + gras_exit(); + return 0; +} diff --git a/doc/gtut-files/3-args.xml b/doc/gtut-files/3-args.xml new file mode 100644 index 0000000000..274c91cad1 --- /dev/null +++ b/doc/gtut-files/3-args.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/doc/gtut-files/Makefile b/doc/gtut-files/Makefile index 99ba5a9f81..b5bed1558e 100644 --- a/doc/gtut-files/Makefile +++ b/doc/gtut-files/Makefile @@ -1,7 +1,7 @@ # This works mainly on my box for now export LD_LIBRARY_PATH=$(GRAS_ROOT)/lib -all: 1-bones 2-simple +all: 1-bones.output 2-simple.output 3-args.output veryclean: clean rm *.output @@ -9,7 +9,6 @@ veryclean: clean # Lesson 1: simple bones of project ######################################## -1-bones: 1-bones.output 1-bones.output: 1-bones_client 1-bones_server 1-bones_simulator echo '$$ ./test_client' > $@ ./1-bones_client >> $@ 2>&1 @@ -32,7 +31,6 @@ clean:: # Lesson 2: simple message exchange ######################################## -2-simple: 2-simple.output 2-simple.output: 2-simple_client 2-simple_server 2-simple_simulator echo '$$ ./test_simulator platform.xml test.xml' > $@ ./2-simple_simulator gtut-platform.xml test.xml >> $@ 2>&1 @@ -48,4 +46,25 @@ clean:: if [ -e 2-simple.mk ] ; then make -f 2-simple.mk clean; fi rm -f _2-simple_client.c _2-simple_server.c _2-simple_simulator.c 2-simple.trace 2-simple.mk -.PHONY: 1-bones 2-simple +# Lesson 3: passing args to processes +######################################## + +3-args.output: 3-args_client 3-args_server 3-args_simulator + echo '$$ ./test_server 12345 & ./test_client 127.0.0.1 12345' > $@ + ./3-args_server 12345 >> $@ 2>&1& + ./3-args_client 127.0.0.1 12345 >> $@ 2>&1 + sleep 1 + echo '$$ ./test_simulator platform.xml test.xml' >> $@ + ./3-args_simulator gtut-platform.xml 3-args.xml >> $@ 2>&1 + echo '$$' >> $@ + +3-args_client 3-args_server 3-args_simulator: _3-args_client.c _3-args_server.c _3-args_simulator.c + make -f 3-args.mk + +_3-args_client.c _3-args_server.c _3-args_simulator.c: 3-args.c test.xml + ../../tools/gras/gras_stub_generator 3-args test.xml >/dev/null + +clean:: + if [ -e 3-args.mk ] ; then make -f 3-args.mk clean; fi + rm -f _3-args_client.c _3-args_server.c _3-args_simulator.c 3-args.trace 3-args.mk + -- 2.20.1