0

I need to clear the content of a boost::interprocess::message_queue without removing it because some (sending) instances may be using it. There seems to be no member method to do so, so I did the following which works. Is there something cleaner/safer to clear the message queue ?

void clear(boost::interprocess::message_queue& mq)
{
    std::string buffer;
    buffer.resize(mq.get_max_msg_size());
    unsigned long _1;
    unsigned int _2;
    while (mq.get_num_msg() > 0)
    {
        mq.try_receive((void*)buffer.data(), mq.get_max_msg_size(), _1, _2);
    }
}
c_drik
  • 63
  • 1
  • 6

0 Answers0