POSIX message queue changes from 20020301?

Joel Sherrill joel.sherrill at OARcorp.com
Thu Dec 5 23:37:50 UTC 2002



Jay Monkman wrote:
> 
> I'm trying to update my application from the 20020301 snapshot to the
> latest one, and some code that uses POSIX message queues now fails.
> 
> I create and open a message queue for read/write. Then I open it again
> (as in another thread) write-only. When I write to the second instance of
> it, I get an error - "Bad file number".

Yep.  You have switched from the old message queue implementation which
was based upon a misinterpretation of the POSIX specification. 
Logically
there are N mqueue descriptors and M mqueues so you have to configure
them
separately.  In this example you have 1 queue and 2 queue descriptors.
Unfortunately, you can't configure the numbers separately now so
increase the message queues to 2.  

There really should be a configuration parameter for number of mqueue
descriptors.  I will look at fixing that tomorrow.

> Here's a test case the causes the problem:
> 
> void qtest(void)
> {
>     struct mq_attr attr;
>     mqd_t mqfd_rw;
>     mqd_t mqfd_wo;
>     int errno;
>     char buf[] = "this is a test buffer";
> 
>     attr.mq_msgsize = 400;
>     attr.mq_maxmsg = 50;
> 
>     mqfd_rw = mq_open("msgq", (O_CREAT|O_RDWR), (S_IRUSR|S_IWUSR), &attr);
> 
>     mqfd_wo = mq_open("msgq", O_WRONLY);
> 
>     if (mq_send(mqfd_wo, buf, strlen(buf), 10) == -1) {
>         printf("mq_send returned an error: %d (%s)\n", errno, strerror(errno));
>         sleep(15);
>         rtemsReboot();
>     }
> }
> 
> Am I doing something I'm not supposed to be doing? Thanks for any help.
> 
> --
> Jay Monkman         The truth knocks on the door and you say "Go away, I'm
>                     looking for the truth," and so it goes away. Puzzling.
>                      - from _Zen_and_the_Art_of_Motorcycle_Maintenance_

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985



More information about the users mailing list