I am new to boost asio. I've read this comparison: How does libuv compare to Boost/ASIO? (Dead link)
It turned out that there is an opportunity to use asio's event loop for other reasons but socket programming. I am planning to use this async event loop for processing messages coming from the UI.
So far I have a concurrent queue and I would like to implement my own boost::asio IO object. The goal is to use this object as you can see here:
#include <iostream>
#include <boost/asio.hpp>
#include "MProcessor.h"
#include "concurrent_queue.h"
void foo(const boost::system::error_code& /*e*/)
{
std::cout << "got message" << std::endl;
}
int main()
{
concurrent_queue<int> messages;
/* ... */
boost::asio::io_service io;
MProcessor t(io, &messages);
t.async_wait(&foo);
io.run();
return 0;
}
So the aim is to keep busy the io_service by an IO object which is able to call a function asynchronously (foo), when the queue (messages) has a message can be popped. The queue has a method called wait_and_pop. It blocks the caller thread until the queue has something to pop, than it returns with the popped item value.
I am stucked at this point, and I couldn't find any boost asio tutorial online without sockects. There are some similar questions, but those all use sockets.
Any idea how to implement my own IO object? Or am I missing any important obstacles? Thank you very much!