Skip to content

Instantly share code, notes, and snippets.

@mwotton
Created March 15, 2012 06:07
Show Gist options
  • Save mwotton/2042350 to your computer and use it in GitHub Desktop.
Save mwotton/2042350 to your computer and use it in GitHub Desktop.
#include <czmq.h>
#include <stdio.h>
void asend(char * t, void * s) {
zmsg_t * msg = zmsg_new();
zmsg_pushstr(msg,t);
zmsg_send(&msg,s);
}
void change_options(void * cvoid, zctx_t * ctx, void * pipe) {
puts("forked\n");
void * s = zsocket_new(ctx, ZMQ_SUB);
zsocket_connect(s, "inproc://test");
zsockopt_set_unsubscribe(s, "");
zsockopt_set_subscribe(s, "foo");
asend("ok", pipe);
zmsg_dump(zmsg_recv(s));
zsockopt_set_unsubscribe(s, "foo");
zsockopt_set_subscribe(s, "bar");
zmsg_dump(zmsg_recv(s));
zmsg_dump(zmsg_recv(s));
zmsg_dump(zmsg_recv(s));
zmsg_dump(zmsg_recv(s));
asend("ok",pipe);
}
main() {
zctx_t * context = zctx_new();
void * pipe = zthread_fork(context, change_options, NULL);
void * s = zsocket_new(context, ZMQ_PUB);
zsocket_bind(s, "inproc://test");
zmsg_recv(pipe);
asend("bar-1",s);
asend("foo1",s);
asend("bar0",s);
asend("foo2",s);
asend("foo3",s);
asend("foo4",s);
asend("bar1",s);
asend("foo5",s);
asend("bar2",s);
asend("foo6",s);
asend("bar3",s);
asend("foo7",s);
asend("bar4",s);
zmsg_recv(pipe);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment