简体   繁体   English

POSIX 消息队列连接问题:mq_open No such file or directory

[英]POSIX message queue connection issue: mq_open No such file or directory

#define MESSAGE_QUEUE_NAME "/project"    

int main (int argc, char **argv){
    char user_name[USER_NAME_LEN];
    mqd_t qd_server;
    int flags;

   if (argc != 2) {
       printf ("Usage: %s user-name\n", argv[0]);
       exit (EXIT_FAILURE);
   }
   strcpy (user_name, argv[1]);
   printf ("User %s connecting to server\n", user_name);

   if ((qd_server = mq_open (SERVER_QUEUE_NAME, O_WRONLY)) == -1) {
       perror ("Client: mq_open (server)");
       exit (1);
   }
   …

I tried to open the message queue before sending a message to the queue.我尝试在向队列发送消息之前打开消息队列。 Before sending a message, I need to open queue server, but when I run it, the error said:在发送消息之前,我需要打开队列服务器,但是当我运行它时,错误说:

Client: mq_open (server): No such file or directory

I just have no idea what is going on.我只是不知道发生了什么。

According to the man page , you are getting the ENOENT error number because "The O_CREAT flag was not specified in oflag, and no queue with this name exists."根据手册页,您收到 ENOENT 错误号,因为“O_CREAT 标志未在 oflag 中指定,并且不存在具有此名称的队列”。

So, you may have not created your message queue.因此,您可能尚未创建消息队列。 You can create it if it does not exist by changing your call to mq_open to mq_open(SERVER_QUEUE_NAME, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR, NULL) .如果它不存在,您可以通过将您对mq_open的调用mq_openmq_open(SERVER_QUEUE_NAME, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR, NULL)来创建它。 Instead of passing NULL as the attr argument, you can specify your own mq_attr struct with the maximum queue length and message size.您可以使用最大队列长度和消息大小指定自己的mq_attr结构,而不是将NULL作为attr参数传递。

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

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