some fixes
This commit is contained in:
parent
e4e75b378b
commit
08d6fac3d2
@ -6,7 +6,7 @@
|
|||||||
int file_write (const char *path, const char *buf, size_t msize)
|
int file_write (const char *path, const char *buf, size_t msize)
|
||||||
{
|
{
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
fprintf (stderr, "file_write: buf == NULL path : %s\n", path);
|
fprintf (stderr, "file_write: buf == NULL\n");
|
||||||
return -1;
|
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);
|
// printf("file_write: path to open %s\n", path);
|
||||||
int fd = open (path, O_WRONLY);
|
int fd = open (path, O_WRONLY);
|
||||||
if (fd <= 0) {
|
if (fd <= 0) {
|
||||||
printf("file_write: fd < 0 path : %s\n", path);
|
printf("file_write: fd < 0\n");
|
||||||
perror ("file_write");
|
perror ("file_write");
|
||||||
return ER_FILE_OPEN;
|
return ER_FILE_OPEN;
|
||||||
}
|
}
|
||||||
// TODO debug
|
|
||||||
// printf("file_write: opened file %s\n", path);
|
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int ret2 = 0;
|
int ret2 = 0;
|
||||||
|
printf ("%ld bytes to write\n", msize);
|
||||||
ret = write (fd, buf, msize);
|
ret = write (fd, buf, msize);
|
||||||
if (ret < 0) {
|
if (ret <= 0) {
|
||||||
fprintf (stderr, "err: written %s buf = %s\n", path, buf);
|
fprintf (stderr, "err: written %s\n", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret2 = close (fd);
|
ret2 = close (fd);
|
||||||
@ -59,7 +58,6 @@ 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);
|
||||||
}
|
}
|
||||||
@ -163,7 +161,6 @@ 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);
|
||||||
|
@ -9,19 +9,21 @@ void * pongd_thread(void * pdata) {
|
|||||||
struct process *proc = (struct process*) pdata;
|
struct process *proc = (struct process*) pdata;
|
||||||
|
|
||||||
// about the message
|
// about the message
|
||||||
size_t msize = BUFSIZ;
|
size_t msize = 0;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// printf ("before read\n");
|
// printf ("before read\n");
|
||||||
|
while (ret <= 0 || msize == 0) {
|
||||||
if ((ret = srv_read (proc, &buf, &msize)) == -1) {
|
if ((ret = srv_read (proc, &buf, &msize)) == -1) {
|
||||||
fprintf(stdout, "MAIN_LOOP: error service_read %d\n", ret);
|
fprintf(stdout, "MAIN_LOOP: error service_read %d\n", ret);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// printf ("after read\n");
|
// printf ("after read\n");
|
||||||
printf ("read, size %ld : %s\n", msize, buf);
|
printf ("read, size %ld : %s\n", msize, buf);
|
||||||
|
|
||||||
if(msize > 0) {
|
if (strncmp ("exit", buf, 4) != 0) {
|
||||||
//printf ("before proc write\n");
|
//printf ("before proc write\n");
|
||||||
if ((ret = srv_write (proc, buf, msize)) == -1) {
|
if ((ret = srv_write (proc, buf, msize)) == -1) {
|
||||||
fprintf(stdout, "MAIN_LOOP: error service_write %d\n", ret);
|
fprintf(stdout, "MAIN_LOOP: error service_write %d\n", ret);
|
||||||
@ -31,6 +33,8 @@ void * pongd_thread(void * pdata) {
|
|||||||
free(buf);
|
free(buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
ret = 0;
|
||||||
|
msize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -3,7 +3,4 @@
|
|||||||
REP=/tmp/ipc/
|
REP=/tmp/ipc/
|
||||||
SERVICE="tcpd"
|
SERVICE="tcpd"
|
||||||
|
|
||||||
# pid index version
|
|
||||||
echo "listen 127.0.0.1 6000" > ${REP}${SERVICE}
|
echo "listen 127.0.0.1 6000" > ${REP}${SERVICE}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
REP=/tmp/ipc/
|
REP=/tmp/ipc/
|
||||||
SERVICE="tcpd"
|
SERVICE="tcpd"
|
||||||
NB=5
|
NB=3
|
||||||
|
|
||||||
if [ $# -ne 0 ]
|
if [ $# -ne 0 ]
|
||||||
then
|
then
|
||||||
@ -16,7 +16,6 @@ do
|
|||||||
mkfifo ${REP}${pid}-1-1-in 2>/dev/null
|
mkfifo ${REP}${pid}-1-1-in 2>/dev/null
|
||||||
mkfifo ${REP}${pid}-1-1-out 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}
|
echo "connect 127.0.0.1 6000 ${pid} 1 1" > ${REP}${SERVICE}
|
||||||
|
|
||||||
# the purpose is to send something in the pipe
|
# the purpose is to send something in the pipe
|
||||||
|
@ -195,7 +195,7 @@ void * service_thread(void * c_data) {
|
|||||||
nbMessages++;
|
nbMessages++;
|
||||||
} else if (n == 0 && nbMessages == 0){
|
} else if (n == 0 && nbMessages == 0){
|
||||||
//message end to server
|
//message end to server
|
||||||
if(file_write(pathname[1], "e", 0) < 0) {
|
if(file_write(pathname[1], "exit", 4) < 0) {
|
||||||
perror("file_write");
|
perror("file_write");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user