QSocketNotifier vs nanomsg
QSocketNotifier vs nanomsg
如果接收到任何数据,是否可以为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,这样构造函数块一结束它就被销毁了。
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 如何为模板化对象创建模板向量?VS正在投掷C3203
- 数据成员SFINAE的C++17测试:gcc vs clang
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 正在VS调试器中监视映射条目
- Confusion: decltype vs std::function
- 将IBM Rhapsody模型集成到VS 2019中
- VS Code "command":"make"与终端窗口中的命令行"make"不同
- 使用VS Code和CMake Tools运行自定义命令
- 修改 VS Code 中的默认C++代码段
- 如何使用c++在VS 2019上运行SQL查询
- vs 2015 constexpr变量不恒定,但与2019相比还好吗
- 完美前进使用 std::forward vs RefRefCast
- 从VS 2015更新3更新到VS2015更新3 d后浮点计算行为不同的原因
- VS 2015 链接错误 无法构建依赖于 libcurl 的项目
- consteval wrapper vs. source_location
- VS Code C++:不准确的系统包括路径错误(wchar.h,boost/lambda/lambda.hpp)
- QStringList vs list<shared_ptr<QString>> 性能比较C++
- QSocketNotifier vs nanomsg