[zeromq-dev] publish/subscribe hangs in libzmq
Joshua Foster
jhawk28 at gmail.com
Fri Dec 30 15:22:00 CET 2011
Try adding a sleep after the pub.connect(). pub/sub throws away data if it has not finished connecting.
Joshua
On Dec 30, 2011, at 9:15 AM, Toralf Wittner wrote:
> Please consider the following program:
>
> #include <zmq.hpp>
> #include <iostream>
>
> int main() {
> zmq::context_t ctx(0);
>
> zmq::socket_t pub(ctx, ZMQ_PUB);
> zmq::socket_t sub(ctx, ZMQ_SUB);
>
> sub.setsockopt(ZMQ_SUBSCRIBE, "", 0);
> sub.bind("inproc://endpoint");
> pub.connect("inproc://endpoint");
>
> char const* data = "hello";
> zmq::message_t hi(const_cast<char*>(data), 5, NULL);
> pub.send(hi);
>
> zmq::message_t msg;
> sub.recv(&msg);
>
> std::cout << static_cast<char*>(msg.data()) << std::endl;
>
> return 0;
> }
>
> Running against 0MQ 2.1.11 yields the expected result:
>
> $ g++ -g -ggdb -O0 -Wall -o testcase-cpp -I/opt/zeromq2-1/include/
> -L/opt/zeromq2-1/lib testcase.cc -lzmq
> $ ./testcase-cpp
> hello
>
> Compiling and running against libzmq (current HEAD
> 6f32361fea61619fec94348de693a9e3ff8981e0) will not terminate. Here the
> stacktraces:
>
> $ g++ -g -ggdb -O0 -Wall -o testcase-cpp -I/opt/zeromq3-1/include/
> -L/opt/zeromq3-1/lib testcase.cc -lzmq
> $ gdb testcase-cpp
> GNU gdb (GDB) 7.3.1
> Copyright (C) 2011 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law. Type "show copying"
> and "show warranty" for details.
> This GDB was configured as "x86_64-unknown-linux-gnu".
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>...
> Reading symbols from /home/user/workspaces/zeromq/testcase-cpp...done.
> (gdb) run
> Starting program: /home/user/workspaces/zeromq/testcase-cpp
> [Thread debugging using libthread_db enabled]
> [New Thread 0x7ffff6c5f700 (LWP 1630)]
> ^C
> Program received signal SIGINT, Interrupt.
> 0x00007ffff7151173 in poll () from /lib/libc.so.6
> (gdb) thread apply all bt
>
> Thread 2 (Thread 0x7ffff6c5f700 (LWP 2053)):
> #0 0x00007ffff71599c3 in epoll_wait () from /lib/libc.so.6
> #1 0x00007ffff7bba49f in zmq::epoll_t::loop (this=0x604610) at epoll.cpp:142
> #2 0x00007ffff7bca1b6 in thread_routine (arg_=0x604680) at thread.cpp:74
> #3 0x00007ffff6c67df0 in start_thread () from /lib/libpthread.so.0
> #4 0x00007ffff71593ed in clone () from /lib/libc.so.6
> #5 0x0000000000000000 in ?? ()
>
> Thread 1 (Thread 0x7ffff7fca720 (LWP 2050)):
> #0 0x00007ffff7151173 in poll () from /lib/libc.so.6
> #1 0x00007ffff7bc5361 in zmq::signaler_t::wait (this=<optimized out>,
> timeout_=<optimized out>) at signaler.cpp:145
> #2 0x00007ffff7bbd33a in zmq::mailbox_t::recv (this=0x606c90,
> cmd_=0x7fffffffe220, timeout_=<optimized out>) at mailbox.cpp:69
> #3 0x00007ffff7bc64cd in zmq::socket_base_t::process_commands
> (this=0x606aa0, timeout_=<optimized out>, throttle_=false) at
> socket_base.cpp:663
> #4 0x00007ffff7bc6c55 in zmq::socket_base_t::recv (this=0x606aa0,
> msg_=0x7fffffffe350, flags_=0) at socket_base.cpp:600
> #5 0x00007ffff7bcec58 in zmq_recvmsg (s_=0x606aa0,
> msg_=0x7fffffffe350, flags_=0) at zmq.cpp:296
> #6 0x0000000000401b0b in zmq::socket_t::recv (this=0x7fffffffe370,
> msg_=0x7fffffffe350, flags_=0) at /opt/zeromq3-1/include/zmq.hpp:345
> #7 0x000000000040134f in main () at testcase.cc:19
>
> I did not look too closely but it seems that no subscriptions match in
> zmq::xpub_t::xsend, i.e. no pipe is marked as matching and
> dist.send_to_matching will not send out anything (with
> dist.send_to_all this program works just like in 0MQ 2.1.11).
>
> T.
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
More information about the zeromq-dev
mailing list