Obsolete
/
libipc-old
Archived
3
0
Fork 0

pubsub: tests sur les pipes (read, write)

more_to_read
Philippe PITTOLI 2016-09-09 14:44:15 +02:00
parent 4a32978c53
commit cdf975db29
3 changed files with 29 additions and 14 deletions

View File

@ -24,15 +24,24 @@ int file_read (const char *path, char **buf, size_t *msize)
return ER_FILE_OPEN;
}
if (*buf == NULL)
*buf = malloc (BUFSIZ);
int ret = 0;
int ret2 = 0;
ret = read (fd, *buf, BUFSIZ);
if (ret < 0) {
return ret;
if (ret <= 0) {
fprintf (stderr, "err: read %s\n", path);
}
else {
*msize = ret;
}
*msize = ret;
close (fd);
ret2 = close (fd);
if (ret2 < 0) {
fprintf (stderr, "err: close [err: %d] %s\n", ret2, path);
perror ("closing");
}
return ret;
}

View File

@ -34,16 +34,23 @@ main(int argc, char **argv)
while (nb--) {
ret = file_read (path, &buf, &msize);
if (ret == 0) {
printf ("no msg\n");
if (ret <= 0) {
fprintf (stderr, "no msg");
if (ret == ER_FILE_OPEN) {
fprintf (stderr, " ER_FILE_OPEN");
}
fprintf (stderr, "\n");
nb++;
continue;
}
if (msize > 0) {
printf ("msg size %ld\t", msize);
struct pubsub_msg m;
memset (&m, 0, sizeof (struct pubsub_msg));
pubsubd_msg_unserialize (&m, buf, msize);
pubsubd_msg_print (&m);
pubsubd_msg_free (&m);
sleep (1);
}
}
return EXIT_SUCCESS;

View File

@ -48,10 +48,9 @@ main(int argc, char **argv)
pubsubd_msg_print (&msg);
pubsubd_msg_free (&msg);
ret = file_write (path, buf, msize);
if (ret != msize) {
if (ret != (int) msize) {
fprintf (stderr, "msg not written\n");
}
sleep (1);
}
return EXIT_SUCCESS;