如何检查提升消息队列是否存在
How to check if boost message queue exists
我正在使用boost message_queue,我在一个c ++程序中创建队列并在另一个程序中使用它。
我的问题是,有时第一个程序还没有运行,但第二个程序正在运行。
所以当我启动第一个程序时,我想知道队列是否存在。 我不想使用 message_queue::remove((,因为我不想丢失一些数据。
问题是,我怎么知道message_queue"bla_bla_queue"是否存在?
message_queue q(open_only,"q");
根据文档:
打开以前创建的名为"name"的进程共享消息队列。如果队列以前未创建或没有可用资源,则会引发错误。
因此,如果消息队列不存在,您应该能够捕获异常。
一个简单的test_program向我展示了抛出interprocess_exception,错误代码为 7,表示not_found_error
。
创建它并用try
和catch
包围。阅读文档以查找already_exists的错误代码(针对您的特定版本的提升((或类似内容(
查看 Boost 1.55 文档以获取该版本中的示例
具体来说,看一下链接的代码:
namespace boost {
namespace interprocess {
enum error_code_t { no_error = = 0, system_error, other_error,
security_error, read_only_error, io_error, path_error,
not_found_error, busy_error, already_exists_error,
not_empty_error, is_directory_error,
out_of_space_error, out_of_memory_error,
out_of_resource_error, lock_error, sem_error,
mode_error, size_error, corrupted_error,
not_such_file_or_directory, invalid_argument,
timeout_when_locking_error,
timeout_when_waiting_error };
typedef int native_error_t;
}
}
有一个
already_exists_error
相关文章:
- boost::进程间消息队列引发错误
- 避免使用 boost::进程间::消息队列创建文件
- 提升消息队列 跨两个进程未接收
- 可以将Boost消息队列文件重定向到用户指定的位置
- 使用加速进程间创建消息队列 - 内存访问冲突
- 如何检查提升消息队列是否存在
- Win32 消息队列在使用 OpenGL 渲染时被淹没
- 在尝试使用boost时断言.跨很多过程中的互动消息队列
- GetMessage/PeekMessage - 删除消息队列中的所有消息
- IPC Unix 消息队列线程安全吗?
- 在.c文件接收函数中使用Linux中的MSGGET创建消息队列未实现错误
- boost消息队列线程安全和进程安全吗?
- 为什么我的无锁消息队列段错误:(?
- 在控制台应用程序中处理空的windows消息队列
- 关于在这种情况下消息队列与共享内存的适用性或适用性
- boost::进程间消息队列创建时的竞争条件
- 从内存转储中查找线程消息队列中的消息
- win32消息泵,do dispatchMessage()处理整个消息队列或仅仅是顶部消息
- 如何使用Boost进程间消息队列for Windows
- 来自另一个线程的 SendMessage() 调用是否将消息发布到消息队列