ZMQ民意调查无法正常工作 [英] ZMQ poll not working

查看:61
本文介绍了ZMQ民意调查无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行以下代码时,第一次调用 zmq_poll 时出错(即返回 -1 )。 zmq_errno()返回 128 zmr_strerror(128)调用返回未知错误 。我已经将ZMQ和C ++一起使用了一段时间,没有任何问题,但是无论多么简单,我都无法调用 zmq_poll 来工作。

When I run the following code, I get an error on the first call to zmq_poll (i.e. it returns -1). The zmq_errno() returns 128 and the zmr_strerror(128) call returns "Unknown error". I have been using ZMQ with C++ for a while now without any problems, but I can't get a call to zmq_poll to work, no matter how simple it is.

调用 zmq :: version 显示我正在使用ZMQ版本2.1.10。

Calling zmq::version reveals that I am using ZMQ version 2.1.10.

有人对为什么 zmq_poll 失败的想法有想法吗?

Does anyone have an idea as to why zmq_poll is failing?

#include <zmq/zmq.hpp>

int main(int argc, char* argv[])
{
    zmq::context_t context(1);
    zmq::socket_t repA(context, ZMQ_REP);
    zmq::socket_t repB(context, ZMQ_REP);
    repA.bind("tcp://127.0.0.1:5555");
    repB.bind("tcp://127.0.0.1:5556");
    zmq::pollitem_t items[] =
    {
        { &repA, 0, ZMQ_POLLIN, 0 },
        { &repB, 0, ZMQ_POLLIN, 0 }
    };
    while (true)
    {
        int rc = zmq_poll(items, 2, 1000);
        if (rc < 0)
        {
            int code = zmq_errno(); //code = 128
            auto message = zmq_strerror(code); //message = "Unknown error"
        }
    }
}


推荐答案


要获取用于zmq_pollitem_t结构的ØMQ套接字,应将socket_t类的实例转换为(void *)。

To obtain a ØMQ socket for use in a zmq_pollitem_t structure, you should cast an instance of the socket_t class to (void *).

所以应该是

zmq::pollitem_t items[] =
{
    { repA, 0, ZMQ_POLLIN, 0 },
    { repB, 0, ZMQ_POLLIN, 0 }
};

没有&

这篇关于ZMQ民意调查无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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