error when trying when using mq_open on linux

193 Views Asked by At

I am trying to open a queue on linux in C++ and it returns a -1 error. how would I debug this issue.

 int32_t MaxMsgs;
    int32_t MaxMsgLength;
    eoMQHndlT msgQptr = -1; 
    char temp[32];
    
    mq_unlink(temp);
    
    struct mq_arrt msQAtt; msQAtt.mq_flags = 0; msQAtt.mq_maxmsg = MaxMsgs; msQAtt.mq_magsize = MaxMsgLength; msQAtt.mq_curmsgs = 0;
    
    msgQptr  = mq_open(temp,O_RDWR|O_CREAT,S_IRUSR | S_IWUSR, &msQAtt);

The variables MaxMsgs and MaxMsgLength are sent it to this call and those values are ex1: MaxMsgs = 10, MaxMsgLength=1232 and ex2:MaxMsgs = 2400, MaxMsgLength=4136 Appreciate some feedback

1

There are 1 best solutions below

6
Thomas Jager On

From the documentation for mq_open (emphasis mine):

RETURN VALUE

On success, mq_open() returns a message queue descriptor for use by other message queue functions. On error, mq_open() returns (mqd_t) -1, with errno set to indicate the error.

So, to debug the issue you have, you should check the value of errno.