简体   繁体   English

实现posix消息队列时出错-“未实现功能”

[英]Error implementing posix message queue - “Function not implemented”

I have written this code to make a posix message queue. 我已经编写了此代码来制作posix消息队列。 But I am receiving an error "Function not implemented". 但是我收到一个错误“功能未实现”。

Q1. Q1。 Is it a platform related issue ? 是平台相关的问题吗? [Am using Ubuntu 10.10] I read somewhere that I need to rebuild my kernel to enable message queues !? [使用Ubuntu 10.10时]我读到某个地方,我需要重建我的内核才能启用消息队列!

Q2. Q2。 I also read something about starting the mqueue server before actually using message queues ? 我还阅读了一些有关在实际使用消息队列之前启动mqueue服务器的信息?

Can someone please explain.. 有人可以解释一下吗。

#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;
}

I think I have realized what the problem was, or rather a mistake from side. 我想我已经意识到问题出在哪里,或者说是一个错误。

This is what I read from here - 这是我从这里读到的-

[ In reference to mq_open( ) ] [参考mq_open()]

Returns: A valid message queue descriptor if the queue is successfully created, or -1 (errno is set). 返回:如果成功创建队列,则为有效的消息队列描述符,或者为-1(设置了errno)。

So, I should be checking the value for errno only when an error actually occurs!. 因此, 当实际发生错误时,我才应检查errno的值! But in the above code I am just printing the value irrespective of an error occured or not, and thus it is printing the error message corresponding to some garbage value stored in errno. 但是在上面的代码中,我只是打印该值,而不管是否发生错误,因此,它正在打印与errno中存储的某些垃圾值相对应的错误消息。

So my code should be something like this - 所以我的代码应该是这样的-

if ((msgQueueDescriptor = mq_open("/myQueue", O_RDWR|O_CREAT, 0664 ,NULL ) == -1))
{
    cout << msgQueueDescriptor << " " << errno << " " << strerror(errno);
}
else
{
   cout << "All is well" ;
} 

Did I just made a fool outa myself :p 我是不是只是自己弄傻了:p

PS: As far as message queues being enabled on Ubuntu 10.10 is concerned, I checked the flags as mentioned by "nm", they are very much enabled, and I am able to use the message queues now. PS:就在Ubuntu 10.10上启用消息队列而言,我检查了“ nm”中提到的标志,它们已启用很多,现在我可以使用消息队列了。 Thanks all of you - larsmans, VJovic, nm, Joachim Pileborg, jørgensen. 谢谢大家-拉尔曼斯(Lasmans),维乔维奇(VJovic),纳米,乔阿希姆·皮尔博格(Joachim PIleborg)和约根森。

About my second question 关于我的第二个问题

Q2. Q2。 I also read something about starting the mqueue server before actually using message queues ? 我还阅读了一些有关在实际使用消息队列之前启动mqueue服务器的信息?

I think that is a requirement specifically on QNX. 我认为这是专门针对QNX的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM