mq_open返回-1,但errno设置为0

时间:2020-07-16 15:25:27

标签: mqueue

我正在将软件包从Windows XP移植到RHEL 7.8,并试图用POSIX mqueue替换Microsoft mailslot。 当我调用mq_open时,它返回-1,但是当我检查errno时,我得到0(成功)。

MsgQueue.h

#include <fnctl.h>
#include <mqueue.h>
#include <string>

class MsgQueue
{
public:
   enum eMode_t
   {
      READ,
      WRITE
   };

   MsgQueue (std::string queueName, eMode_t readWrite);

   void Init ();
...
private:
   std::string m_sMsgQueueName;
   mqd_t mMsgQueue;
   eMode_t m_eReadWrite;
}
'''
**MsgQueue.cpp**
'''
#include <cerrno>

#include "MsgQueue.h"

MsgQueue::MsgQueue (std::string queueName, eMode_t readWrite)
   : m_sMsgQueueName (queueName),
     m_eReadWrite (readWrite)
{
}

void MsgQueue::Init ()
{
   struct mq_attr mq_attrs;
   mq_attrs.mq_flags = 0;
   mq_attrs.mq_maxmsg = 1000;
   mq_attrs.mq_msgsize = 2048;
   mq_attrs.mq_curmsgs = 0;

   if (m_eReadWrite == READ)
   {
      mMsgQueue = mq_open (m_sMsgQueueName.c_str(), O_RDONLY | O_CREAT, 00644, &mq_attrs);

      if (mMsgQueue == (mqd_t) -1)
      {
         perror (errno);
      }
   }
   else
   {
      // open for write
   }
}

有人知道我如何从mq_open获得-1但errno没有设置为任何有用的东西吗?

0 个答案:

没有答案