gpt4 book ai didi

c++ - QSocketNotifier 与 nanomsg

转载 作者:太空宇宙 更新时间:2023-11-04 12:46:17 25 4
gpt4 key购买 nike

是否可以对 nanomsg 套接字使用 QSocketNotifier,以便在收到任何数据时执行某些操作?我尝试使用此代码,但当我运行 nanocat --req --connect ipc:///tmp/node0.ipc --data pong --format ascii 时没有任何反应。我什至不知道如何检查问题发生在哪一步,因为没有错误。

Wrapper::Wrapper(QObject *parent) : QObject(parent) {
...
createNode();
int fd;
size_t sz = sizeof(fd);
nn_getsockopt(sock, NN_SOL_SOCKET, NN_RCVFD, &fd, &sz);
QSocketNotifier m_notifier(fd, QSocketNotifier::Read);
QObject::connect(&m_notifier, SIGNAL(activated(int)), this, SLOT(nmsgRecieve()));
m_notifier.setEnabled(true);
...
}

void Wrapper::createNode() {
const char* url = "ipc:///tmp/node0.ipc";

if ((sock = nn_socket(AF_SP, NN_REP)) < 0) {
qDebug() << "nn_socket" << nn_strerror(nn_errno());
exit(1);
}
if ((rv = nn_bind(sock, url)) < 0) {
qDebug() << "nn_bind" << nn_strerror(nn_errno());
exit(1);
}
}

void Wrapper::nmsgRecieve() {
qDebug() << "Some msg";
char *buf = NULL;
int bytes;
if ((bytes = nn_recv(sock, &buf, NN_MSG, 0)) < 0) {
qDebug() << "nn_recv" << nn_strerror(nn_errno());
exit(1);
}
qDebug() << buf;
nn_freemsg(buf);
}

最佳答案

好吧,这是一个非常愚蠢的问题,与 nanomsg 或 QSocketNotifier 无关。我创建了我的 QSocketNotifer,以便它在构造函数 block 结束时立即被销毁。

关于c++ - QSocketNotifier 与 nanomsg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51383252/

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