首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >POSIX4消息队列"mq_open:没有这样的文件或目录“

POSIX4消息队列"mq_open:没有这样的文件或目录“
EN

Stack Overflow用户
提问于 2016-09-10 20:47:16
回答 1查看 3.5K关注 0票数 2

我正在尝试使用POSIX4消息队列。因此,我使用mq_open来创建队列,对于所有的选项,我给它一个struct mq_attr,我填充。

当我放置O_CREATE标志时,他找不到队列。

下面是我的代码(没有缩进的行是调试代码)

代码语言:javascript
复制
...
/***
 * 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);
}
...

这是输出:

代码语言:javascript
复制
serveur first sizeof(gui_action) : 16   msgsize : 16
mq_open: No such file or directory

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-11 00:02:02

on failure and a message queue descriptor on success.

您将mq_open的成功返回(实际上是整数>= 0)误认为是失败,而perror正在报告一些以前的系统调用的errno

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39430447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档