Obsolete
/
libipc-old
Archived
3
0
Fork 0

pubsubd: test pipes

more_to_read
Philippe PITTOLI 2016-09-09 13:29:36 +02:00
parent 0524f70bab
commit 4a32978c53
2 changed files with 59 additions and 0 deletions

View File

@ -42,6 +42,7 @@ main(int argc, char **argv)
struct pubsub_msg m;
pubsubd_msg_unserialize (&m, buf, msize);
pubsubd_msg_print (&m);
pubsubd_msg_free (&m);
sleep (1);
}

58
pubsub/test-pipe-write.c Normal file
View File

@ -0,0 +1,58 @@
#include "../lib/pubsubd.h"
#include <stdlib.h>
#define CHAN "chan1"
#define MESSAGE "coucou"
void
ohshit(int rvalue, const char* str) {
fprintf(stderr, "%s\n", str);
exit(rvalue);
}
void usage (char **argv) {
fprintf (stderr, "usage: %s path times\n", argv[0]);
fprintf (stderr, "ex: %s /tmp/pipe 5 => you will write 5 times\n", argv[0]);
exit (1);
}
int
main(int argc, char **argv)
{
if (argc != 3)
usage (argv);
char *path = argv[1];
int nb = atoi (argv[2]);
printf ("Writing on %s %d times.\n", path, nb);
char *buf = NULL;
size_t msize = 0;
int ret = 0;
while (nb--) {
struct pubsub_msg msg;
memset (&msg, 0, sizeof (struct pubsub_msg));
msg.type = PUBSUB_TYPE_MESSAGE;
msg.chan = malloc (strlen (CHAN) + 1);
strncpy ((char *)msg.chan, CHAN, strlen (CHAN) + 1);
msg.chanlen = strlen (CHAN) + 1;
msg.data = malloc (strlen (MESSAGE) + 1);
strncpy ((char *)msg.data, MESSAGE, strlen (CHAN) + 1);
msg.datalen = strlen (MESSAGE) + 1;
pubsubd_msg_serialize (&msg, &buf, &msize);
pubsubd_msg_print (&msg);
pubsubd_msg_free (&msg);
ret = file_write (path, buf, msize);
if (ret != msize) {
fprintf (stderr, "msg not written\n");
}
sleep (1);
}
return EXIT_SUCCESS;
}