gpt4 book ai didi

c++ - ZeroMQ 如何管理 zmq::proxy 和 zmq::poll 中的套接字?

转载 作者:行者123 更新时间:2023-11-28 06:05:54 24 4
gpt4 key购买 nike

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

实际上 ZeroMQ 希望用户发送一个在 void* ( source of the information ) 中转换的结构

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

编辑:这是我认为正确的代码

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

实际工作的代码是这个:

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

这对我来说很奇怪。为什么 ZeroMQ 会这样做?

最佳答案

这里面没有什么奇怪的。

socket_t 中存在一个指针类和运算符 static_cast<void *>()方法返回此指针而不是使用类的实际实例。

Can a cast operator be explicit?

这篇文章帮助我理解了 official documentation test of zmq 中出现的问题.在c++11中是不可能直接使用的

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

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

zmq::proxy(static_cast<void *>(frontend_), static_cast<void *>(backend_), nullptr);

关于c++ - ZeroMQ 如何管理 zmq::proxy 和 zmq::poll 中的套接字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32417941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com