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; return ER_FILE_OPEN;
} }
if (*buf == NULL)
*buf = malloc (BUFSIZ);
int ret = 0; int ret = 0;
int ret2 = 0;
ret = read (fd, *buf, BUFSIZ); ret = read (fd, *buf, BUFSIZ);
if (ret < 0) { if (ret <= 0) {
return ret; fprintf (stderr, "err: read %s\n", path);
}
else {
*msize = ret;
} }
*msize = ret; ret2 = close (fd);
if (ret2 < 0) {
close (fd); fprintf (stderr, "err: close [err: %d] %s\n", ret2, path);
perror ("closing");
}
return ret; return ret;
} }

View File

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

View File

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