ZeroMQ 如何管理 zmq::proxy 和 zmq::poll 中的套接字? [英] How does ZeroMQ manage socket in zmq::proxy and zmq::poll?

查看:36
本文介绍了ZeroMQ 如何管理 zmq::proxy 和 zmq::poll 中的套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 ZeroMQ 的问题,因为我在 zmq::proxy 和 zmq::poll 的 ZMQ 套接字上使用了指针.这样做会发生错误 88(非套接字上的套接字操作)的异常.

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).

实际上,ZeroMQ 希望用户发送一个在 void* 中强制转换的结构(信息来源)

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

我在官方文档中做了一些研究,但我没有发现为什么 ZeroMQ 不在套接字上使用指针.

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

这是我认为正确的代码

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

这对我来说很奇怪.ZeroMQ 为什么要这样做?

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

推荐答案

没有什么奇怪的.

socket_t 类中存在一个指针,并且操作符 static_cast<void *>() 方法返回该指针而不是使用该类的实际实例.

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.

强制转换运算符可以是显式的吗?

这篇文章帮助我理解了官方文档测试zmq<中出现的问题/代码>.在c++11中不能直接使用

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

因为转换在 zmq 代码中是显式的.所以你需要像这样正确地投射套接字:

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

这篇关于ZeroMQ 如何管理 zmq::proxy 和 zmq::poll 中的套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆