[英]Error implementing posix message queue - “Function not implemented”
我已经编写了此代码来制作posix消息队列。 但是我收到一个错误“功能未实现”。
Q1。 是平台相关的问题吗? [使用Ubuntu 10.10时]我读到某个地方,我需要重建我的内核才能启用消息队列!
Q2。 我还阅读了一些有关在实际使用消息队列之前启动mqueue服务器的信息?
有人可以解释一下吗。
#include <mqueue.h> /* message queue stuff */
#include <iostream>
#include <unistd.h> /* for getopt() */
#include <errno.h> /* errno and perror */
#include <fcntl.h> /* O_flags */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main(int argc, char **argv)
{
mqd_t msgQueueDescriptor;
mq_attr attr;
char Msg[]="msg";
attr.mq_maxmsg = 10;
attr.mq_msgsize = sizeof(Msg);
attr.mq_flags = 0;
msgQueueDescriptor = mq_open("/myQueue", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH , attr );
cout << msgQueueDescriptor << " " << errno << " " << strerror(errno);
mq_close(msgQueueDescriptor);
return 0;
}
我想我已经意识到问题出在哪里,或者说是一个错误。
这是我从这里读到的-
[参考mq_open()]
返回:如果成功创建队列,则为有效的消息队列描述符,或者为-1(设置了errno)。
因此, 仅当实际发生错误时,我才应检查errno的值! 但是在上面的代码中,我只是打印该值,而不管是否发生错误,因此,它正在打印与errno中存储的某些垃圾值相对应的错误消息。
所以我的代码应该是这样的-
if ((msgQueueDescriptor = mq_open("/myQueue", O_RDWR|O_CREAT, 0664 ,NULL ) == -1))
{
cout << msgQueueDescriptor << " " << errno << " " << strerror(errno);
}
else
{
cout << "All is well" ;
}
我是不是只是自己弄傻了:p
PS:就在Ubuntu 10.10上启用消息队列而言,我检查了“ nm”中提到的标志,它们已启用很多,现在我可以使用消息队列了。 谢谢大家-拉尔曼斯(Lasmans),维乔维奇(VJovic),纳米,乔阿希姆·皮尔博格(Joachim PIleborg)和约根森。
关于我的第二个问题
Q2。 我还阅读了一些有关在实际使用消息队列之前启动mqueue服务器的信息?
我认为这是专门针对QNX的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.