Obsolete
/
libipc-old
Archived
3
0
Fork 0

adapted pingpong apllication for the new version ex: pid-ind_in -> pid-ind-ver-in

more_to_read
lapupe 2016-09-15 15:34:56 +02:00
parent 74d7a87738
commit 34ced4437a
4 changed files with 12 additions and 9 deletions

View File

@ -59,6 +59,7 @@ int file_read (const char *path, char **buf, size_t *msize)
int ret = 0; int ret = 0;
int ret2 = 0; int ret2 = 0;
ret = read (fd, *buf, BUFSIZ); ret = read (fd, *buf, BUFSIZ);
if (ret < 0) { if (ret < 0) {
fprintf (stderr, "err: read %s\n", path); 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; char *buf = NULL;
size_t msize = 0; size_t msize = 0;
int ret = file_read (srv->spath, &buf, &msize); int ret = file_read (srv->spath, &buf, &msize);
if (ret <= 0) { if (ret <= 0) {
fprintf (stderr, "err: listening on %s\n", srv->spath); fprintf (stderr, "err: listening on %s\n", srv->spath);
exit (1); exit (1);

View File

@ -1,6 +1,6 @@
CC=gcc CC=gcc
CFLAGS=-Wall -g CFLAGS=-Wall -g
LDFLAGS= LDFLAGS= -pthread
CFILES=$(wildcard *.c) # CFILES => recompiles everything on a C file change CFILES=$(wildcard *.c) # CFILES => recompiles everything on a C file change
EXEC=$(basename $(wildcard *.c)) EXEC=$(basename $(wildcard *.c))
SOURCES=$(wildcard ../lib/*.c) SOURCES=$(wildcard ../lib/*.c)

View File

@ -21,7 +21,6 @@ void main_loop (const struct service *srv)
// -1 : error, 0 = no new process, 1 = new process // -1 : error, 0 = no new process, 1 = new process
ret = srv_get_new_process (srv, &proc); ret = srv_get_new_process (srv, &proc);
//printf("ret = %d\n", ret);
if (ret == -1) { if (ret == -1) {
fprintf (stderr, "MAIN_LOOP: error service_get_new_process\n"); fprintf (stderr, "MAIN_LOOP: error service_get_new_process\n");

View File

@ -8,7 +8,9 @@ NB=10
if [ $# -ne 0 ] && [ "$1" = clean ] if [ $# -ne 0 ] && [ "$1" = clean ]
then then
echo "clean rep ${REP}" 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 exit 0
fi fi
@ -21,19 +23,19 @@ fi
for pid in `seq 1 ${NB}` for pid in `seq 1 ${NB}`
do do
# we make the application pipes # we make the application pipes
mkfifo ${REP}${pid}-1-in 2>/dev/null mkfifo ${REP}${pid}-1-5-in 2>/dev/null
mkfifo ${REP}${pid}-1-out 2>/dev/null mkfifo ${REP}${pid}-1-5-out 2>/dev/null
# pid index version # pid index version
echo "${pid} 1 5" > ${REP}${SERVICE} echo "${pid} 1 5" > ${REP}${SERVICE}
# the purpose is to send something in the pipe # the purpose is to send something in the pipe
cat /dev/urandom | base64 | head -n 1 > ${REP}${pid}-1-out cat /dev/urandom | base64 | head -n 1 > ${REP}${pid}-1-5-out
# echo "hello world" > ${REP}${pid}-1-out # echo "hello world" > ${REP}${pid}-1-5-out
# the the service will answer with our message # the the service will answer with our message
echo "pid : ${pid}" echo "pid : ${pid}"
cat ${REP}/${pid}-1-in cat ${REP}${pid}-1-5-in
done done
echo "clean rep" echo "clean rep"