Problem with "Message Queue Size"

Hi,



Problem with “Message Queue Size”.



One of our applications needs to send messages of size greater than 4K over message queue. Whenever we try to do the same, it is failing to send the message. Please help us to sort out the issue as early as possible. Issue is described as follows:



Environment:



QNX version 6.2.1 on x86 as well as on SH4 (Biscayne)



Description:

We are able to create a message queue which can handle message size greater than the default, but unable to send messages over the queue with size more than the default (4K). Error we are receiving is “Message too long”



Please find attached the code that we used to test the same.

Regards
Jabir K.M

qnx std <jabir.kannath@wipro.com> wrote:

Hi,

Problem with “Message Queue Size”.



One of our applications needs to send messages of size greater than
4K over message queue. Whenever we try to do the same, it is failing
to send the message. Please help us to sort out the issue as early
as possible. Issue is described as follows:

Environment:

QNX version 6.2.1 on x86 as well as on SH4 (Biscayne)

Description:

We are able to create a message queue which can handle message size
greater than the default, but unable to send messages over the queue
with size more than the default (4K). Error we are receiving is
“Message too long”

Please find attached the code that we used to test the same.

I found no attached code.

I used the following test case on a 6.3.0 machine (no, not 6.2.1, but
I checked our PR logs, and there is no record of a bug fix/change for
this behaviour, so I would expect the same behaviour).


#include <stdio.h>
#include <string.h>
#include <mqueue.h>
#include <errno.h>

char buf[8192];

int main()
{
int mq_d;
struct mq_attr mqattr;
int ret;

memset(&mqattr, 0, sizeof(mqattr));

mqattr.mq_maxmsg = 10;
mqattr.mq_msgsize = 8192;
mqattr.mq_flags = O_NONBLOCK;

mq_d = mq_open("/myqueue", O_CREAT|O_RDWR, 0666, &mqattr);
printf(“mq_open returned %d, errno %d\n”, mq_d, errno );

ret = mq_send(mq_d, buf, 8192, 10);
printf(“send of 8192 bytes returned %d, errno %d\n”, ret, errno );

ret = mq_receive(mq_d, buf, 8192, NULL);
printf(“receive of 8192 bytes returned %d, errno %d\n”, ret, errno);
return 0;
}

Please try this, or post (cut & paste or include in the text of
your message, not as an attachment) your (simple) code that fails.

-David

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

David Gibbs <dagibbs@qnx.com> wrote:

qnx std <> jabir.kannath@wipro.com> > wrote:

Ah, you did post the code elsewhere… it was broken code:

void* thread(void* unused)
{
mqd_t tQueue;
char* pcChar = “Hello world…”;

tQueue = mq_open("/dev/mqueue/testq",O_RDWR,(S_IRWXU | S_IRWXG | S_IRWXO),
NULL);
printf("\n Sending message - %s\n",pcChar);
if(-1 == mq_send(tQueue,pcChar,4098,10))

You can’t send 4K of data from a 20 byte buffer.

-David

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

Hi Mr. David Gibbs,



The test code was quickly written by one of my team member for sending it to
you; I didn’t review the same too. Sorry for the inconvenience caused.



Anyway, based on the snippet you provided, we will do the necessary
modifications. Hope that the message size problem will be solved.



Thanks a lot for the support you are providing.



Regards

Jabir

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:d1pr6d$5n1$4@nntp.qnx.com

David Gibbs <> dagibbs@qnx.com> > wrote:
qnx std <> jabir.kannath@wipro.com> > wrote:

Ah, you did post the code elsewhere… it was broken code:

void* thread(void* unused)
{
mqd_t tQueue;
char* pcChar = “Hello world…”;

tQueue = mq_open("/dev/mqueue/testq",O_RDWR,(S_IRWXU | S_IRWXG | S_IRWXO),
NULL);
printf("\n Sending message - %s\n",pcChar);
if(-1 == mq_send(tQueue,pcChar,4098,10))

You can’t send 4K of data from a 20 byte buffer.

-David

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

Dave/John,



Thank you very much for your assistance. I tried out the code provided by
you and it works fine. I’ve to still get over the mortification of having
sent out that code snippet in the earlier mail. .



The reason for the problem we were facing is message queue persistence. When
the application terminates (usually killed from the command line), the
message queue continues to exist in memory. The next time the app starts
(with some changes to the mqueue attributes in the code), the mqueue is
reopened with the older attributes (in our case, max message size) even
though we “O_CREAT” the mqueue with different attributes (higher max message
size).The error would only become apparent when we tried sending messages
greater than the previous “max message size”. This means that with an
O_CREAT request, “mq_open()” ignores the “mq_attr” data if the specified
mqueue already exists and “O_EXCL” is not specified. This sounds pretty
obvious but I had overlooked it :frowning:



We believe we will not face this problem in production code and, so, that no
programmatic changes are required.



Regards,

Jabir.



“David Gibbs” <dagibbs@qnx.com> wrote in message
news:d1pr6d$5n1$4@nntp.qnx.com

David Gibbs <> dagibbs@qnx.com> > wrote:
qnx std <> jabir.kannath@wipro.com> > wrote:

Ah, you did post the code elsewhere… it was broken code:

void* thread(void* unused)
{
mqd_t tQueue;
char* pcChar = “Hello world…”;

tQueue = mq_open("/dev/mqueue/testq",O_RDWR,(S_IRWXU | S_IRWXG | S_IRWXO),
NULL);
printf("\n Sending message - %s\n",pcChar);
if(-1 == mq_send(tQueue,pcChar,4098,10))

You can’t send 4K of data from a 20 byte buffer.

-David

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