C++ mq_取消链接的限制是什么?

C++ mq_取消链接的限制是什么?,c++,posix,C++,Posix,说 搪瓷 名字太长了 但这个限制是什么?我以为它是NAME\u MAX,但它不是。以下代码将永远运行(我想,只要有内存) #包括 #包括 #包括 #包括 内部主(空) { std::string tooLong=“long”; 做 { usleep(10); tooLong.追加(“更长”); mq_unlink(tooLong.c_str()); } while(errno!=enametolong); } 那么限制是什么呢?此函数何时返回ENAMETOOLONG?谢谢,您是对的 问题是缺少

搪瓷 名字太长了

但这个限制是什么?我以为它是
NAME\u MAX
,但它不是。以下代码将永远运行(我想,只要有内存)

#包括
#包括
#包括
#包括
内部主(空)
{
std::string tooLong=“long”;
做
{
usleep(10);
tooLong.追加(“更长”);
mq_unlink(tooLong.c_str());
}
while(errno!=enametolong);
}
那么限制是什么呢?此函数何时返回ENAMETOOLONG?

谢谢,您是对的


问题是缺少斜线

#include <mqueue.h>
#include <string>
#include <errno.h>
#include <unistd.h>
#include <iostream>
#include <limits.h>

int main(void)
{
    std::string tooLong = "/long";
    do
    {
        usleep(10);
        tooLong.append("longer");
        mq_unlink(tooLong.c_str());
    }
    while(errno != ENAMETOOLONG);
    std::cout << tooLong.length() << " " << tooLong << std::endl;    
}
#包括
#包括
#包括
#包括
#包括
#包括
内部主(空)
{
std::string tooLong=“/long”;
做
{
usleep(10);
tooLong.追加(“更长”);
mq_unlink(tooLong.c_str());
}
while(errno!=enametolong);

std::在假设有错误之前,您是否应该检查函数的返回值。您的名称似乎格式不正确。据我所知,当字符串长度变为257个字符时,即超过255的
name\u MAX
长度时,它会停止。“问题是缺少斜杠!”,没有。问题是您没有查看
mq\u unlink()
的错误值。您可以避免这个问题,因为您有良好的实践,请阅读
#include <mqueue.h>
#include <string>
#include <errno.h>
#include <unistd.h>
#include <iostream>
#include <limits.h>

int main(void)
{
    std::string tooLong = "/long";
    do
    {
        usleep(10);
        tooLong.append("longer");
        mq_unlink(tooLong.c_str());
    }
    while(errno != ENAMETOOLONG);
    std::cout << tooLong.length() << " " << tooLong << std::endl;    
}