Skip to content

Instantly share code, notes, and snippets.

@robinp robinp/Main.java
Created Jan 7, 2011

Embed
What would you like to do?
jzmq bug reproduce
package zmqbugtest;
import org.zeromq.ZMQ;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Main().run();
}
Main() {
}
private void run() {
ctx = ZMQ.context(1);
String addr = "inproc://bind1";
ZMQ.Socket sock1 = ctx.socket(ZMQ.PUB);
sock1.bind(addr);
ZMQ.Socket sock2 = ctx.socket(ZMQ.SUB);
ZMQ.Socket sock3 = ctx.socket(ZMQ.SUB);
ZMQ.Poller poller = ctx.poller();
int poll2 = poller.register(sock2);
int poll3 = poller.register(sock3);
poller.unregister(sock2);
byte any_topic[] = {};
sock2.connect(addr);
sock2.subscribe(any_topic);
sock3.connect(addr);
sock3.subscribe(any_topic);
sleep(100);
byte[] msg = {'h', 'e', 'l', 'l', 'o'};
sock1.send(msg, 0);
sleep(100);
long ret = poller.poll();
System.out.println("pollin 2: " + poller.pollin(poll2) );
System.out.println("pollin 3: " + poller.pollin(poll3) );
System.out.println( "2: " + new String(sock2.recv(0)) );
System.out.println( "3: " + new String(sock3.recv(0)) );
}
private void sleep(long m) {
try {
Thread.sleep(m);
}
catch (InterruptedException e) {
// pass
}
}
private ZMQ.Context ctx;
}
/*
Patched output:
pollin 2: false
pollin 3: true
2: hello
3: hello
Unpatched output:
pollin 2: true
pollin 3: false (sometimes true)
2: hello
3: hello
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.