How does ZeroMQ manage socket in zmq::proxy and zmq::poll?

混江龙づ霸主 提交于 2019-12-12 06:06:26

问题


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 ?


回答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);


来源:https://stackoverflow.com/questions/32417941/how-does-zeromq-manage-socket-in-zmqproxy-and-zmqpoll

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!