views:

2156

answers:

2

I've noticed that boost.asio has a lot of examples involving sockets, serial ports, and all sorts of non-file examples. Google hasn't really turned up a lot for me that mentions if asio is a good or valid approach for doing asynchronous file i/o.

I've got gobs of data i'd like to write to disk asynchronously. This can be done with native overlapped io in Windows (my platform), but I'd prefer to have a platform independent solution.

I'm curious if

  1. boost.asio has any kind of file support
  2. boost.asio file support is mature enough for everyday file i/o
  3. Will file support ever be added? Whats the outlook for this?
+6  A: 

Starting with (I think) Boost 1.36 (which contains Asio 1.2.0) you can use [boost::asio::]windows::stream_handle or windows::random_access_handle to wrap a HANDLE and perform asynchronous read and write methods on it that use the OVERLAPPED structure internally.

vividos
Thanks, that may prove useful. Do you know of any plans to implement a platform independent asynchronous file?
Doug T.
Not that I know of, sorry. There is a posix::stream_descriptor class that does the same for posix handles, so at least a wrapper for the two approaches could be written.
vividos
@vividos: I believe that the posix::stream_descriptor will not work with regular files. See http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/overview/posix/stream_descriptor.html.
villintehaspam
I also read that on the boost.asio.users list some time ago; seems there's no way with Boost.Asio...http://thread.gmane.org/gmane.comp.lib.boost.asio.user/4043
vividos
+2  A: 

boost::asio::windows::random_access_handle is the easiest way to do this, if you need something advanced, for example asynchronous LockFileEx or something else, you might extend asio, add your own asynchronous events. example

Lazin