6

The solution in the post below doesn't work for me. I get error message "Message too long". What can be the problem? How to send integer with message queue with POSIX API in linux?

If I am correct a pid_t is defined as an int. I have done the following:

struct mq_attr attr;
attr.mq_flags = 0;
attr.mq_maxmsg = 1000;
attr.mq_msgsize = sizeof(pid_t);

mqd_t queue = mq_open(unique_name, O_RDWR|O_CREAT, 0600, &attr);

mqd_t result = mq_send(queue, &pid, sizeof(pid), 0);

I get the following error at compilation at the line of mq_send:

"passing argument 2 of 'mq_send' from incompatible pointer type"
"initialization makes pointer from integer without a cast"

Community
  • 1
  • 1
user1766169
  • 1,932
  • 3
  • 22
  • 44
  • Did you specify a msgsize when you called `mq_open`? You might want to post the open and send calls. – Duck Nov 07 '12 at 20:28
  • Sizeof int should be immaterial since you specify sizeof pid_t. That looks ok to me. Sorry, it was worth a try. – Duck Nov 08 '12 at 02:48

2 Answers2

4

The problem was that I never did mq_unlink.

user1766169
  • 1,932
  • 3
  • 22
  • 44
  • if you want to avoid having to unlink, then just code `if ((queue == -1) && (errno != EEXIST))`. Of course, if the queue is already open, you might want to flush it before proceeding. – Mawg says reinstate Monica May 25 '16 at 12:33
1

You probably want to set the maximum message size and queue size with an mq_attr first. See this post for more detail on POSIX queues.

Community
  • 1
  • 1
Joe
  • 7,378
  • 4
  • 37
  • 54