我正在尝试使用POSIX4消息队列。因此,我使用mq_open来创建队列,对于所有的选项,我给它一个struct mq_attr,我填充。
当我放置O_CREATE标志时,他找不到队列。
下面是我的代码(没有缩进的行是调试代码)
...
/***
* Queues' names
*/
#define GUI_QUEUE "/guiQ"
...
struct mq_attr attrAct; /* Queue parameters */
/***
* Message queue to send action
*/
attrAct.mq_maxmsg=1;
attrAct.mq_msgsize=sizeof(gui_action);
attrAct.mq_flags=0;
attrAct.mq_curmsgs=0;
printf("serveur first sizeof(gui_action) : %lu\tmsgsize : %lu\n", sizeof(gui_action), attrAct.mq_msgsize);
if ((guiQue=mq_open(GUI_QUEUE, O_CREAT | O_NONBLOCK | O_WRONLY
, S_IWUSR | S_IRUSR , &attrAct))!=0) {
perror("mq_open");
exit(EXIT_FAILURE);
}
if (mq_getattr(guiQue, &attrAct)!=0) {
perror("mq_getattr");
}
else {
printf("serveur second sizeof(gui_action) : %lu\tmsgsize : %lu\n", sizeof(gui_action), attrAct.mq_msgsize);
}
struct mq_attr new;
new=attrAct;
new.mq_msgsize=sizeof(gui_action);
printf("serveur third sizeof(gui_action) : %lu\tmsgsize : %lu\n", sizeof(gui_action), new.mq_msgsize);
if (mq_setattr(guiQue, &new, &attrAct)!=0) perror("mq_setattr");
if (mq_getattr(guiQue, &attrAct)!=0) {
perror("mq_getattr");
}
else {
printf("serveur fourth sizeof(gui_action) : %lu\tmsgsize : %lu\n", sizeof(gui_action), attrAct.mq_msgsize);
}
...这是输出:
serveur first sizeof(gui_action) : 16 msgsize : 16
mq_open: No such file or directory我做错了什么?
发布于 2016-09-11 00:02:02
on failure and a message queue descriptor on success.
您将mq_open的成功返回(实际上是整数>= 0)误认为是失败,而perror正在报告一些以前的系统调用的errno。
https://stackoverflow.com/questions/39430447
复制相似问题