Why ZeroMQ poll throws an error: "socket operation on non-socket"?

Viewed 1374

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.
  }
}
1 Answers
Related