diff --git a/lib/communication.c b/lib/communication.c index 415a1dc..46d604e 100644 --- a/lib/communication.c +++ b/lib/communication.c @@ -6,7 +6,7 @@ int file_write (const char *path, const char *buf, size_t msize) { if (buf == NULL) { - fprintf (stderr, "file_write: buf == NULL path : %s\n", path); + fprintf (stderr, "file_write: buf == NULL\n"); return -1; } @@ -14,18 +14,17 @@ int file_write (const char *path, const char *buf, size_t msize) // printf("file_write: path to open %s\n", path); int fd = open (path, O_WRONLY); if (fd <= 0) { - printf("file_write: fd < 0 path : %s\n", path); + printf("file_write: fd < 0\n"); perror ("file_write"); return ER_FILE_OPEN; } - // TODO debug - // printf("file_write: opened file %s\n", path); - + int ret = 0; int ret2 = 0; + printf ("%ld bytes to write\n", msize); ret = write (fd, buf, msize); - if (ret < 0) { - fprintf (stderr, "err: written %s buf = %s\n", path, buf); + if (ret <= 0) { + fprintf (stderr, "err: written %s\n", path); } ret2 = close (fd); @@ -59,7 +58,6 @@ 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); } @@ -161,9 +159,8 @@ 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/pingpong.c b/pingpong/pingpong.c index a981bb3..8a46937 100644 --- a/pingpong/pingpong.c +++ b/pingpong/pingpong.c @@ -9,19 +9,21 @@ void * pongd_thread(void * pdata) { struct process *proc = (struct process*) pdata; // about the message - size_t msize = BUFSIZ; + size_t msize = 0; char *buf = NULL; - int ret; + int ret = 0; while (1) { // printf ("before read\n"); - if ((ret = srv_read (proc, &buf, &msize)) == -1) { - fprintf(stdout, "MAIN_LOOP: error service_read %d\n", ret); + while (ret <= 0 || msize == 0) { + if ((ret = srv_read (proc, &buf, &msize)) == -1) { + fprintf(stdout, "MAIN_LOOP: error service_read %d\n", ret); + } } // printf ("after read\n"); printf ("read, size %ld : %s\n", msize, buf); - if(msize > 0) { + if (strncmp ("exit", buf, 4) != 0) { //printf ("before proc write\n"); if ((ret = srv_write (proc, buf, msize)) == -1) { fprintf(stdout, "MAIN_LOOP: error service_write %d\n", ret); @@ -31,6 +33,8 @@ void * pongd_thread(void * pdata) { free(buf); break; } + ret = 0; + msize = 0; } return NULL; diff --git a/remote/script/testServer.sh b/remote/script/testServer.sh index b7e4291..29c5169 100755 --- a/remote/script/testServer.sh +++ b/remote/script/testServer.sh @@ -3,7 +3,4 @@ REP=/tmp/ipc/ SERVICE="tcpd" -# pid index version echo "listen 127.0.0.1 6000" > ${REP}${SERVICE} - - diff --git a/remote/script/testTcpd.sh b/remote/script/testTcpd.sh index cd111de..233a6d6 100755 --- a/remote/script/testTcpd.sh +++ b/remote/script/testTcpd.sh @@ -2,7 +2,7 @@ REP=/tmp/ipc/ SERVICE="tcpd" -NB=5 +NB=3 if [ $# -ne 0 ] then @@ -16,7 +16,6 @@ do mkfifo ${REP}${pid}-1-1-in 2>/dev/null mkfifo ${REP}${pid}-1-1-out 2>/dev/null - # pid index version echo "connect 127.0.0.1 6000 ${pid} 1 1" > ${REP}${SERVICE} # the purpose is to send something in the pipe @@ -28,4 +27,4 @@ do echo "pid : ${pid}" cat ${REP}/${pid}-1-1-in -done \ No newline at end of file +done diff --git a/remote/tcpdserver.c b/remote/tcpdserver.c index 6670104..57bd06a 100644 --- a/remote/tcpdserver.c +++ b/remote/tcpdserver.c @@ -195,7 +195,7 @@ void * service_thread(void * c_data) { nbMessages++; } else if (n == 0 && nbMessages == 0){ //message end to server - if(file_write(pathname[1], "e", 0) < 0) { + if(file_write(pathname[1], "exit", 4) < 0) { perror("file_write"); }