Reputation: 41
#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.
Upvotes: 1
Views: 1440
Reputation: 314
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."
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)
. Instead of passing NULL
as the attr
argument, you can specify your own mq_attr
struct with the maximum queue length and message size.
Upvotes: 3