-1

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

0

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

6 Comments

I am getting a value of -1 for msgQptr . I am assuming that is the errno?
how do I print the errno?
No, errno is a separate variable that is set by various functions to indicate the specific error. -1 just indicates that there was an error. From the return value section here, there is a link to the errno manual page.
And from that page, it tells you that you can use perror and strerror to print an error message to stderr.
when I did perror("mq_open") - for 2 different instances I get - Too many open files and invalid argument. How do I debug this?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.