Boost logo

Boost :

From: Christopher Kohlhoff (chris_at_[hidden])
Date: 2005-09-06 06:45:00


Hi Felipe,

--- Felipe Magno de Almeida <felipe.m.almeida_at_[hidden]> wrote:
> I've implemented asynchronous file IO for linux in asio using aio_*
> functions.
> I created a class called basic_stream_file (and a typedef called
> stream_file) with almost the same interface as basic_stream_socket.
> But with read/write and async_read/async_write functions and an
> aio_demuxer_service. I writed it for the 0.3.2 version.

Nice! It didn't really require that much code either, which is
impressive.

> I didnt had time to test it very much, but it seems to be working
> okay. There are some problems that are related to aio_* in linux,
> since it isnt completely implemented in today's kernels and isnt
> implemented at all in 2.4.* kernels(there are patches however). And
> the aio_* functions only work really asynchronous for now if used
> with
> O_DIRECT and aligned buffers. But at least it could have a single
> interface for AIO with files in Windows and Linux.

Yeah, I can't really think of a good solution to the problem of
correctly aligning the buffers. We may have to provide some sort of
allocator object that is guaranteed to return buffers correctly aligned
for the read and write operations.

> Any feedback will be appreciated.

My only suggestion at this time is that rather than trying to
reimplement all the demuxer code (for doing dispatch(), post() etc),
just use the task_demuxer_service and implement the aio code as a task.
A task must have the following interface:

class Task
{
public:
  void reset(); // Reset in preparation for a new run() call.
  void run(); // Perform operations until interrupted.
  void interrupt(); // Stop an existing run loop.
};

Note that the interrupt() function must be able to be called from a
different thread to run().

You then use your demuxer like so:

typedef basic_demuxer<
  detail::task_demuxer_service<detail::aio_task> > aio_demuxer;

If you look at the select_reactor or epoll_reactor you will see that
they implement the above Task concept, but they also support running
themselves in a separate thread. This is one way to have aio for files
and select_reactor/epoll_reactor for sockets coexist in the same
demuxer object.

Cheers,
Chris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk