【问题标题】:CZMQ set send HWM / set receive HWMCZMQ 设置发送 HWM / 设置接收 HWM
【发布时间】:2021-11-22 06:40:15
【问题描述】:

这不是必须的吗?

#include <czmq.h>

zsock_t *sockout = zsock_new_pub("inproc://a");
zsock_set_sndhwm (sockout, 20);

如何设置 HWM 和/或 BUF 大小?

更新: 我添加了更多代码并在这种情况下工作:

#include <string>
#include <czmq.h>

int main (void){

    zsock_t *sockout = zsock_new_pub("inproc://a");
    zsock_set_sndhwm (sockout, 20);
    std::string data2send;
    for (size_t i = 0; i < 1000; i++){
        data2send = "data" + std::to_string(i);
        zsock_send(sockout, "s", data2send.c_str() );
    }
}

尽管zsock_set_sndhwm (sockout, 20); 在这个特定的上下文中工作。 我必须弄清楚它不起作用的上下文。

【问题讨论】:

  • 您上面的代码不包含可执行代码块。

标签: c++ zeromq czmq


【解决方案1】:

我正在回答我自己的问题,以获得完整的解决方案 pub/rec

发布者代码:

#include <string>
#include <czmq.h>

int main (void)
{
    zsock_t *sockout = zsock_new_pub("ipc://a");
    zsock_set_sndhwm (sockout, 20);
    zsock_set_rcvhwm (sockout, 20);

    std::string data2send;
    for (size_t i = 0; i < 1000; i++){
        data2send = "data: " + std::to_string(i);
        sleep(1);
        zsock_send(sockout, "s", data2send.c_str() );
    }
}

订阅者(接收者)代码:

#include <string>
#include <czmq.h>
#include <iostream>

int main (void){
    zsock_t *sockin = zsock_new_sub("ipc://a", "");
    zsock_set_sndhwm (sockin, 20);
    zsock_set_rcvhwm (sockin, 20);

    char *m;
    std::string m_str;

    while(true){
        zsock_recv(sockin, "s", &m);
        std::cout << "**READ: " << m << "\n\n";
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-20
    相关资源
    最近更新 更多