I encounter a serious and odd issue with ZeroMQ and its C++ binding: each time I perform a polling operation on zmq socket, it throws an error of:
socket operation on non-socket
Below is the code to reproduce it:
#include <zmq.hpp>
int main() {
zmq::context_t ctx(1);
zmq::socket_t sock1( ctx, ZMQ_REQ );
zmq::socket_t sock2( ctx, ZMQ_PUB );
sock1.bind( "tcp://*:10001" );
sock2.bind( "tcp://*:10002" );
zmq::pollitem_t* items = ( zmq::pollitem_t* ) malloc( 2 * sizeof( zmq::pollitem_t ) );
items[0] = { &sock1, 0, ZMQ_POLLIN, 0 };
items[1] = { &sock2, 0, ZMQ_POLLIN, 0 };
while(1) {
zmq::poll ( items, 2, 500 ); // Throws error !! socket operation on non-socket.
}
}
Given ZeroMQ API / C++ binding documentation recommends to do so, one ought follow a practice to:
To obtain a ØMQ socket for use in a
zmq_pollitem_t
structure, you should cast an instance of thesocket_t
class to(void *)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With