c++ - 如何检查boost消息队列是否存在

标签 c++ boost message-queue

我正在使用 boost message_queue,并在一个 C++ 程序中创建队列并在另一个程序中使用它。

我的问题是,有时第一个程序尚未运行,但第二个程序正在运行。

所以当我启动第一个程序时,我想知道队列是否存在。 我不想使用 message_queue::remove() 因为我不想丢失一些数据。

问题是,我如何知道 message_queue "bla_bla_queue"是否存在?

message_queue q(open_only,"q");

最佳答案

根据doc :

Opens a previously created process shared message queue with name "name". If the queue was not previously created or there are no free resources, throws an error.

因此,如果消息队列不存在,您应该能够捕获异常。

一个simple test_program告诉我,interprocess_exception抛出错误,错误码为7,表示not_found_error .

关于c++ - 如何检查boost消息队列是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50839639/

相关文章:

.net - 在评估消息队列时,开发人员/架构师应该寻找什么品质?

c++ - 如何将 CString 转换为 long? VC++

c++ - 在另一台计算机上运行 a.out

c++ - 如何在C++中实现静态类?

sql-server - RabbitMQ、ZeroMQ、Service Broker 或类似的解决方案是否适合创建高可用性数据库 Web 服务?

python - 需要一个线程安全的异步消息队列

c++ - 我可以以某种方式将套接字从winsock2.h传递到unique_ptr并为他制作自定义删除器吗?

c++ - BGL : vertices in listS and index_map

c++ - 什么时候将 C++ 函数放在头文件中

linux - "Compiler threading support is not turned on."