I have just discovered the reason why my libevent program did not receive any more ZeroMq messages after the first one. It seems that, after creating the ZeroMq socket, you have to read until you get a EAGAIN error or you will not set the socket events in the right state. If you don’t do so, the idea libevent and ZeroMq have about that socket will not match, so your program will not receive/send anything.
From this thread:
The socket is initially considered ready for reading & writing. Given that ZMQ_FD is edge triggered, you won’t get next event unless you fail to send/recv a message.
So, when you create a socket, you have to do something like this:
zsocket = new zmq::socket_t (*ZMqLink::m_pZContext, ZMQ_XREQ); /* read until EAGAIN */ while (TRUE) { zmq::message_t msg; bool more = zsocket->recv(&msg, ZMQ_NOBLOCK); if (!more) break; } /* now we can get the zsocket fd */ int fd = (-1); size_t fd_size = sizeof(fd); zocket->getsockopt(ZMQ_FD, &fd, &fd_size); /* ... and register it with libevent for EV_READ */ 原文地址:http://inercia.tumblr.com/post/3600122381/zeromq-with-libevent-cont