boost::asio::io_service and posix message queues
I'm working on a project where we want a single thread to asynchronously interact with posix message queues, TCP sockets and drivers. From what I've read, boost::asio::io_service provides a common framework dealing with asynchronous IO. It looks like there's a asio library for TCP and posix::stream_descriptor could be used for interacting with a driver file descriptor. What I don't see is support for posix message queues. The io_service documentation states the following: "The io_service class also includes facilities intended for developers of custom asynchronous services.". I was thinking of adding a custom service for posix message queues. Has anyone already done this? Is there any fundamental reason why it could not be done? (i.e. message queues are not byte streams, etc.) Thanks, Sergio
I didn't get a response to my email, but I ended up figuring out how
to use POSIX message queues with the boost::asio::io_service. Under
Linux you use select/epoll with message queue descriptors. I ended up
using boost::asio::posix::stream_descriptor to interact with message
queues. You can specify boost::asio::null_buffers() for the
async_read_some() and async_write_some() calls. These usually do
some reading or writing, but with null_buffers() they do not do any
reading or writing. You get a callbacks when the select/epoll
indicates that a message queue can be written to or read from. In the
callbacks, you can do the actual mq_send() and mq_receive() calls.
I've written some test code and included it below. There is one
message queue, a reader thread, and a writer thread. The writer
thread uses a timer to send a message through the message queue every
100 ms. The reader thread wakes up immediately to process the
messages.
-- Sergio
#include <iostream>
#include <string>
#include
I'm working on a project where we want a single thread to asynchronously interact with posix message queues, TCP sockets and drivers. From what I've read, boost::asio::io_service provides a common framework dealing with asynchronous IO. It looks like there's a asio library for TCP and posix::stream_descriptor could be used for interacting with a driver file descriptor. What I don't see is support for posix message queues.
The io_service documentation states the following: "The io_service class also includes facilities intended for developers of custom asynchronous services.".
I was thinking of adding a custom service for posix message queues. Has anyone already done this? Is there any fundamental reason why it could not be done? (i.e. message queues are not byte streams, etc.)
Thanks, Sergio
participants (1)
-
Sergio Martinez