Boost消息队列文件可以重定向到用户指定的位置

问题描述 投票:1回答:1

如何将Boost消息队列文件的创建重定向到用户指定的目录。我正在使用ubuntu。当前,它是在/ dev / shm位置上创建的。文件与消息队列名称相同。我尝试定义宏BOOST_INTERPROCESS_SHARED_DIR_FUNC并实现了功能get_shared_dir。但这是行不通的。下面是我的代码:文件:message_queue_dir_path.h

    #include <string>
    namespace boost {
        namespace interprocess {
            namespace ipcdetail {
                void get_shared_dir(std::&shared_dir){
                    shared_dir = "/home/username/message_queue_dir";
                }
           }
       }
    }

并在编译时在BOOST_INTERPROCESS_SHARED_DIR_FUNC中定义宏。但是它仍然没有在给定位置创建文件。转到/ dev / shm

c++ boost boost-interprocess
1个回答
0
投票

我在CentOS 7上调试了类似的情况,发现是:在Linux上,无法使用get_shared_dir更改shared_dir。它将在/ dev / shm中(或者您的tmpfs挂载在哪里)。

原因是在Linux上,boost_ message_queue在内部使用“ shm_open”。而且shm_open仅允许使用“对象名称”,而不是文件路径。

在Windows上,您的解决方案很吸引人。

如果您想看一下代码,可以在boost \ interprocess \ shared_memory_object.hpp中找到,函数shared_memory_object :: priv_open_or_create。

相关问题:how do i change the shm_open path?

© www.soinside.com 2019 - 2024. All rights reserved.