A small, POSIX compliant(????) PubSub.
I don't know what I'm doing as far as c programming goes, so be careful!
make
Then, start a server that will listen to messages that it should broadcast to subscribers:
./server
Next, add two (or however many you want) subscribers:
./subscribe
Finally, we can publish events to subscribers:
./publish "Hello, world"
If you ctrl + c
the subscriber terminal, it'll return its old PID.
You can "re-subscribe" to the mqueue for that subscriber by using the
resubscribe <pid>
command:
./resubscribe 1337
If you happen to do another publish while a subscriber process is not
running, there will still be a /dev/mqueue/pubsub1337
file. The
./resubscribe
program "reconnects" you to this queue.
If you no longer want to subscribe to this mqueue and you want the
queue to be deleted, you can either do rm /dev/mqueue/pubsub1337
or you can use ./unsubscribe
:
./unsubscribe 1337
I run this after a make cleean
to start from a blank slate:
rm /dev/mqueue/pubsub*