Skip to content

Instantly share code, notes, and snippets.

@danielnorberg
Created December 19, 2011 13:24
Show Gist options
  • Save danielnorberg/1497216 to your computer and use it in GitHub Desktop.
Save danielnorberg/1497216 to your computer and use it in GitHub Desktop.
zeromq 3 pub leak
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include <zmq.h>
#define TOPIC "foobarfoobarfoobarfoobarfoobar"
int main (int argc, const char * argv[])
{
void *ctx = zmq_init (1);
void *pub = zmq_socket (ctx, ZMQ_PUB);
zmq_bind (pub, "tcp://*:4711");
void *sub = zmq_socket (ctx, ZMQ_XSUB);
zmq_connect (sub, "tcp://localhost:4711");
sleep(1);
for (long i = 0;;i++) {
zmq_send(sub, "\1" TOPIC, strlen(TOPIC) + 1, 0);
zmq_send(sub, "\0" TOPIC, strlen(TOPIC) + 1, 0);
if (i % 100 == 0) {
// trigger handling of subscriptions
zmq_send(pub, "baz", 3, 0);
}
// avoid hitting hwm
struct timespec t = { 0, 10000 };
nanosleep(&t, NULL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment