pubsubd: corrections + tests
This commit is contained in:
parent
d754958f9a
commit
0524f70bab
@ -561,19 +561,8 @@ void pubsub_disconnect (struct process *p)
|
||||
pubsubd_msg_serialize (&m, &buf, &msize);
|
||||
|
||||
int ret = app_write (p, buf, msize);
|
||||
switch (ret) {
|
||||
case ER_FILE_WRITE :
|
||||
fprintf (stderr, "err: ER_FILE_WRITE\n");
|
||||
break;
|
||||
case ER_FILE_WRITE_PARAMS :
|
||||
fprintf (stderr, "err: ER_FILE_WRITE_PARAMS\n");
|
||||
break;
|
||||
case ER_FILE_OPEN :
|
||||
fprintf (stderr, "err: ER_FILE_OPEN\n");
|
||||
break;
|
||||
case ER_FILE_CLOSE :
|
||||
fprintf (stderr, "err: ER_FILE_CLOSE\n");
|
||||
break;
|
||||
if (ret != (int) msize) {
|
||||
fprintf (stderr, "err: can't disconnect\n");
|
||||
}
|
||||
|
||||
pubsubd_msg_free (&m);
|
||||
|
@ -40,7 +40,7 @@ main(int argc, char **argv)
|
||||
pubsubd_msg_serialize (&msg, &data, &len);
|
||||
pubsubd_msg_free (&msg);
|
||||
|
||||
if (len != write (1, data, len)) {
|
||||
if ((int) len != write (1, data, len)) {
|
||||
ohshit (1, "unable to write the data");
|
||||
}
|
||||
|
||||
|
49
pubsub/test-pipe-read.c
Normal file
49
pubsub/test-pipe-read.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include "../lib/pubsubd.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define TEST_NAME "test-chan-lists"
|
||||
|
||||
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 read 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 ("Listening on %s %d times.\n", path, nb);
|
||||
|
||||
char *buf = NULL;
|
||||
size_t msize = 0;
|
||||
|
||||
int ret = 0;
|
||||
|
||||
while (nb--) {
|
||||
ret = file_read (path, &buf, &msize);
|
||||
if (ret == 0) {
|
||||
printf ("no msg\n");
|
||||
nb++;
|
||||
continue;
|
||||
}
|
||||
struct pubsub_msg m;
|
||||
pubsubd_msg_unserialize (&m, buf, msize);
|
||||
pubsubd_msg_print (&m);
|
||||
sleep (1);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Reference in New Issue
Block a user