0

I had a problem concerning ZeroMQ because I used pointer on a ZMQ socket for zmq::proxy and zmq::poll. Doing that occurs an exception with error 88 (Socket operation on non-socket).

Actually ZeroMQ wants the user to send a structure cast in void* (source of the information)

I did some research in the official documentation but I didn't found why ZeroMQ doesn't use a pointer on the socket.

edit: This is the code I thought would be correct

zmq::socket_t frontend_;
zmq::socket_t backend_;
zmq::proxy(&frontend_, &backend_, nullptr);

and the code that is actually working is this one :

zmq::socket_t frontend_;
zmq::socket_t backend_;
zmq::proxy((void *)frontend_, (void *)backend_, nullptr);

It's strange for me. Why does ZeroMQ do it ?

Community
  • 1
  • 1
FreeYourSoul
  • 328
  • 4
  • 15

1 Answers1

1

There was nothing strange in it.

A pointer is present in the socket_t class and an operator static_cast<void *>() method is returning this pointer instead of using the actual instance of the class.

Can a cast operator be explicit?

This post helped me to understand that a problem appears in the official documentation test of zmq. In c++11 it's impossible to use directly

zmq::proxy(frontend_, backend_, nullptr);

because the conversion is explicit in the zmq code. So you need to properly cast the socket like that :

zmq::proxy(static_cast<void *>(frontend_), static_cast<void *>(backend_), nullptr);
Community
  • 1
  • 1
FreeYourSoul
  • 328
  • 4
  • 15