0

I have an mqueue which has 2 messages in it but the call to mq_receive will not pull data. I don't have any previous experience with this message queue so forgive my ignorance. I believe the send side is working fine as echoing the "file" does show information.

QSIZE:48 NOTIFY:1 SIGNO:0 NOTIFY_PID:5741

This is 2 messages without a message signal being generated. The PID is the process that will be calling mq_receive.

For reference, here is the open code.

msgq_attr.mq_maxmsg  = MAX_NUM_MESSAGES; // 20
msgq_attr.mq_msgsize = MAX_MSG_SIZE; // 256

mqrcv_id = mq_open(queue_name, O_RDONLY | O_NONBLOCK, 
                  S_IRWXU | S_IRWXO, msgq_attr);

notify.sigev_notify = SIGEV_NONE;    
notify.sigev_notify_attributes = NULL;          
mq_notify(mqrcv_id, &notify);

And here is the receive.

int msgSize = mq_receive(mqrcv_id, buffer,
                        MAX_MSG_SIZE, &msgprio);

msgSize always returns -1 with errno EAGAIN. From the documentation, this should mean that the queue has no messages in it. Note that it is NONBLOCKING.

lostdev
  • 736
  • 8
  • 23
  • It's unlikely we can determine much from this information. Do some basic debugging so you are absolutely certain you actually do send stuff to the proper queue, and that the notification signal is received, and post the relevant part of the code with context (e.g. we can't see where or when your server calls mq_receive, nor can we see that the message is sent properly to the proper queue. – nos May 16 '14 at 13:22
  • The message is in the proper queue. There is no signal that is sent, as I explained in the description of the issue and by the code snipped that has SIGEV_NONE. – lostdev May 16 '14 at 13:31
  • @iostdev Fair enough, which leads to another question, since you're using a non blocking queue, and are not notified of arriving messages, when are you calling mq_receive ? – nos May 16 '14 at 15:11

1 Answers1

0

The issue is a code bug. The call to open should be

mqrcv_id = mq_open(queue_name, O_RDONLY | O_NONBLOCK, 
              S_IRWXU | S_IRWXO, &msgq_attr);
lostdev
  • 736
  • 8
  • 23