Message too long for mqueue_receive()

I am getting a “Message too long” error when I call mq_receive(). I haven’t
written any code to write to the message queue so I don’t understand how the
message could be too long if I haven’t sent it anything yet. Here’s the code:


/** include files **/
#include <unistd.h>
#include <stdio.h>
#include <mqueue.h>

int main(int argc, char *argv[])
{
int iOpt;
char *pStrInputMsgQueue = “/srasku”;
mqd_t mqd;
struct mq_attr mq_attr;
char aBuffer[256];

mq_attr.mq_msgsize = sizeof(aBuffer);
if ( (mqd = mq_open(pStrInputMsgQueue, O_CREAT | O_RDONLY,
0666, NULL) ) == -1)
{
char err[80];
snprintf(err, sizeof(err), “mq_open(%s)”, pStrInputMsgQueue);
perror(err);
}
else
{
unsigned uPriority;
if (-1 == mq_receive(mqd, aBuffer, sizeof(aBuffer),
&uPriority) )
{
perror(“mq_receive”);
}
else
{
fprintf(stdout, “Received message ‘%s’ at priorit %d\n”,
aBuffer, uPriority);
}
(void)mq_close(mqd);
}
return(0);
}

I should have mentioned that this is for QNX 6.2.0.

In article <slrnc0r1l3.23d.spr@granite.rasku.ca>, Stephen Rasku wrote:

I am getting a “Message too long” error when I call mq_receive(). I haven’t
written any code to write to the message queue so I don’t understand how the
message could be too long if I haven’t sent it anything yet. Here’s the code:


/** include files **/
#include <unistd.h
#include <stdio.h
#include <mqueue.h

int main(int argc, char *argv[])
{
int iOpt;
char *pStrInputMsgQueue = “/srasku”;
mqd_t mqd;
struct mq_attr mq_attr;
char aBuffer[256];

mq_attr.mq_msgsize = sizeof(aBuffer);
if ( (mqd = mq_open(pStrInputMsgQueue, O_CREAT | O_RDONLY,
0666, NULL) ) == -1)
{
char err[80];
snprintf(err, sizeof(err), “mq_open(%s)”, pStrInputMsgQueue);
perror(err);
}
else
{
unsigned uPriority;
if (-1 == mq_receive(mqd, aBuffer, sizeof(aBuffer),
&uPriority) )
{
perror(“mq_receive”);
}
else
{
fprintf(stdout, “Received message ‘%s’ at priorit %d\n”,
aBuffer, uPriority);
}
(void)mq_close(mqd);
}
return(0);
}

In article <buk42d$9f1$1@inn.qnx.com>, Chris Foran wrote:

I think the problem is as follows. When you called mq_open(), you specified
NULL as the last argument (the mq attributes). This causes the default
mq_msgsize to be 4096 bytes. I believe that you must then use this size for
the msg_len argument to mq_receive().

The doc for mq_receive() states:

“If you call mq_receive() with a msg_len of anything other than the
mq_msgsize of the specified queue, then mq_receive() returns an error, and
errno is set to EINVAL.”

The error you received is not EINVAL, but I think this may be a problem with
the doc.

Now the mq_receive() is blocking waiting for data. This is what I would
expect. Thanks for the tip.

…Stephen

I think the problem is as follows. When you called mq_open(), you specified
NULL as the last argument (the mq attributes). This causes the default
mq_msgsize to be 4096 bytes. I believe that you must then use this size for
the msg_len argument to mq_receive().

The doc for mq_receive() states:

“If you call mq_receive() with a msg_len of anything other than the
mq_msgsize of the specified queue, then mq_receive() returns an error, and
errno is set to EINVAL.”

The error you received is not EINVAL, but I think this may be a problem with
the doc.


“Stephen Rasku” <spr@shaw.ca> wrote in message
news:slrnc0r1pc.23d.spr@granite.rasku.ca

I should have mentioned that this is for QNX 6.2.0.

In article <> slrnc0r1l3.23d.spr@granite.rasku.ca> >, Stephen Rasku wrote:
I am getting a “Message too long” error when I call mq_receive(). I
haven’t
written any code to write to the message queue so I don’t understand how
the
message could be too long if I haven’t sent it anything yet. Here’s the
code:


/** include files **/
#include <unistd.h
#include <stdio.h
#include <mqueue.h

int main(int argc, char *argv[])
{
int iOpt;
char *pStrInputMsgQueue = “/srasku”;
mqd_t mqd;
struct mq_attr mq_attr;
char aBuffer[256];

mq_attr.mq_msgsize = sizeof(aBuffer);
if ( (mqd = mq_open(pStrInputMsgQueue, O_CREAT | O_RDONLY,
0666, NULL) ) == -1)
{
char err[80];
snprintf(err, sizeof(err), “mq_open(%s)”, pStrInputMsgQueue);
perror(err);
}
else
{
unsigned uPriority;
if (-1 == mq_receive(mqd, aBuffer, sizeof(aBuffer),
&uPriority) )
{
perror(“mq_receive”);
}
else
{
fprintf(stdout, “Received message ‘%s’ at priorit %d\n”,
aBuffer, uPriority);
}
(void)mq_close(mqd);
}
return(0);
}

Stephen Rasku <spr@shaw.ca> wrote:

In article <buk42d$9f1$> 1@inn.qnx.com> >, Chris Foran wrote:
I think the problem is as follows. When you called mq_open(), you specified
NULL as the last argument (the mq attributes). This causes the default
mq_msgsize to be 4096 bytes. I believe that you must then use this size for
the msg_len argument to mq_receive().

The doc for mq_receive() states:

“If you call mq_receive() with a msg_len of anything other than the
mq_msgsize of the specified queue, then mq_receive() returns an error, and
errno is set to EINVAL.”

The error you received is not EINVAL, but I think this may be a problem with
the doc.

Yeah, I"m not clear which is correct here, either, but if you check the
error returns for mq_receive it does mention the EMSGSIZE error.

You can, actually, use a buffer >= the queue size successfully.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.