[IPCPipe] Example using boost message queues

This commit is contained in:
momo5502 2017-01-27 10:51:53 +01:00
parent 454e358882
commit d05cdcb9ea

View File

@ -7,6 +7,7 @@ namespace boost
#pragma warning(push)
#pragma warning(disable: 4091)
#pragma warning(disable: 4996)
#undef sleep
//#define BOOST_DISABLE_WIN32
@ -222,6 +223,38 @@ namespace Components
IPCPipe::IPCPipe()
{
Command::Add("mq1", [](Command::Params*)
{
boost::interprocess::message_queue::remove("message_queue");
//Create a message_queue.
boost::interprocess::message_queue mq(boost::interprocess::create_only, "message_queue", 100, sizeof(int));
int i = 1;
mq.send(&i, sizeof(i), 0);
});
Command::Add("mq2", [](Command::Params*)
{
boost::interprocess::message_queue mq(boost::interprocess::open_only, "message_queue");
unsigned int priority;
boost::interprocess::message_queue::size_type recvd_size;
//Receive 100 numbers
for (int i = 0; i < 3; ++i) {
int number;
if (!mq.try_receive(&number, sizeof(number), recvd_size, priority) || recvd_size != sizeof(number))
{
Logger::Print("Nothing received\n");
}
else
{
Logger::Print("Rec: %d\n", number);
}
}
});
if (Dedicated::IsEnabled()) return;
// Server pipe
@ -258,17 +291,4 @@ namespace Components
IPCPipe::ServerPipe.destroy();
IPCPipe::ClientPipe.destroy();
}
void test()
{
boost::interprocess::message_queue::remove("message_queue");
//Create a message_queue.
boost::interprocess::message_queue mq
(boost::interprocess::create_only //only create
, "message_queue" //name
, 100 //max message number
, sizeof(int) //max message size
);
}
}