From 34ced4437ab1862b55d5e2ca14cda66add2b908a Mon Sep 17 00:00:00 2001 From: lapupe Date: Thu, 15 Sep 2016 15:34:56 +0200 Subject: [PATCH] adapted pingpong apllication for the new version ex: pid-ind_in -> pid-ind-ver-in --- lib/communication.c | 4 +++- pingpong/Makefile | 2 +- pingpong/pingpong.c | 1 - pingpong/pingpong.sh | 14 ++++++++------ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/communication.c b/lib/communication.c index f9620c9..3c1bbd6 100644 --- a/lib/communication.c +++ b/lib/communication.c @@ -59,6 +59,7 @@ int file_read (const char *path, char **buf, size_t *msize) int ret = 0; int ret2 = 0; ret = read (fd, *buf, BUFSIZ); + if (ret < 0) { fprintf (stderr, "err: read %s\n", path); } @@ -160,8 +161,9 @@ int srv_get_new_process (const struct service *srv, struct process *p) } char *buf = NULL; - size_t msize = 0; + size_t msize = 0; int ret = file_read (srv->spath, &buf, &msize); + if (ret <= 0) { fprintf (stderr, "err: listening on %s\n", srv->spath); exit (1); diff --git a/pingpong/Makefile b/pingpong/Makefile index 22d244e..6b95c76 100644 --- a/pingpong/Makefile +++ b/pingpong/Makefile @@ -1,6 +1,6 @@ CC=gcc CFLAGS=-Wall -g -LDFLAGS= +LDFLAGS= -pthread CFILES=$(wildcard *.c) # CFILES => recompiles everything on a C file change EXEC=$(basename $(wildcard *.c)) SOURCES=$(wildcard ../lib/*.c) diff --git a/pingpong/pingpong.c b/pingpong/pingpong.c index dd34e94..9a900c3 100644 --- a/pingpong/pingpong.c +++ b/pingpong/pingpong.c @@ -21,7 +21,6 @@ void main_loop (const struct service *srv) // -1 : error, 0 = no new process, 1 = new process ret = srv_get_new_process (srv, &proc); - //printf("ret = %d\n", ret); if (ret == -1) { fprintf (stderr, "MAIN_LOOP: error service_get_new_process\n"); diff --git a/pingpong/pingpong.sh b/pingpong/pingpong.sh index 7d7eb22..bae1759 100755 --- a/pingpong/pingpong.sh +++ b/pingpong/pingpong.sh @@ -8,7 +8,9 @@ NB=10 if [ $# -ne 0 ] && [ "$1" = clean ] then echo "clean rep ${REP}" - rm ${REP}/${SERVICE} + rm ${REP}/${SERVICE} 2>/dev/null + rm ${REP}/*-in 2>/dev/null + rm ${REP}/*-out 2>/dev/null exit 0 fi @@ -21,19 +23,19 @@ fi for pid in `seq 1 ${NB}` do # we make the application pipes - mkfifo ${REP}${pid}-1-in 2>/dev/null - mkfifo ${REP}${pid}-1-out 2>/dev/null + mkfifo ${REP}${pid}-1-5-in 2>/dev/null + mkfifo ${REP}${pid}-1-5-out 2>/dev/null # pid index version echo "${pid} 1 5" > ${REP}${SERVICE} # the purpose is to send something in the pipe - cat /dev/urandom | base64 | head -n 1 > ${REP}${pid}-1-out - # echo "hello world" > ${REP}${pid}-1-out + cat /dev/urandom | base64 | head -n 1 > ${REP}${pid}-1-5-out + # echo "hello world" > ${REP}${pid}-1-5-out # the the service will answer with our message echo "pid : ${pid}" - cat ${REP}/${pid}-1-in + cat ${REP}${pid}-1-5-in done echo "clean rep"