This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues/pull-requests.
2016-09-08 23:41:15 +02:00
|
|
|
#include "../lib/pubsubd.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define MESSAGE "coucou"
|
|
|
|
#define CHAN "chan1"
|
|
|
|
|
|
|
|
void
|
|
|
|
ohshit(int rvalue, const char* str) {
|
|
|
|
fprintf (stderr, "\033[31merr: %s\033[00m\n", str);
|
|
|
|
exit (rvalue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void usage (char **argv)
|
|
|
|
{
|
|
|
|
printf ( "usage: %s\n", argv[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
if (argc != 1) {
|
|
|
|
usage (argv);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
char *data = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
pubsubd_msg_serialize (&msg, &data, &len);
|
|
|
|
pubsubd_msg_free (&msg);
|
|
|
|
|
2016-09-09 12:33:47 +02:00
|
|
|
if ((int) len != write (1, data, len)) {
|
2016-09-08 23:41:15 +02:00
|
|
|
ohshit (1, "unable to write the data");
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|