Asynchronous Boost.Iostreams with Boost.Asio

I read in the documentation of Boost.Iostreams (at http://www.boost.org/doc/libs/1_35_0/libs/iostreams/doc/guide/asynchronous.h...) that "additional Device concepts will be required for full support of asynchronous i/o". Are there any ideas how these additional devices concepts will/should look like? I ask as I was trying to extend Boost.Asio and add support for C++ standard streams on the weekend. I came to the conclusion that this is impossible (as calls to C++ standard streams block and there is no way to interrupt a blocking call, at least not in a portable way). If there are any ideas though how to support asynchronous I/O with Boost.Iostreams I'd like to hear them. But I guess that would still mean that you can't use C++ standard streams (like std::cin) asynchronously? Boris

Boris wrote:
I ask as I was trying to extend Boost.Asio and add support for C++ standard streams on the weekend. I came to the conclusion that this is impossible (as calls to C++ standard streams block and there is no way to interrupt a blocking call, at least not in a portable way).
The only way to simulate asynchronous I/O using blocking calls is to use a separate thread for every I/O object. Sebastian Redl

On Mon, 07 Apr 2008 11:40:48 +0200, Sebastian Redl <sebastian.redl@getdesigned.at> wrote:
Boris wrote:
I ask as I was trying to extend Boost.Asio and add support for C++ standard streams on the weekend. I came to the conclusion that this is impossible (as calls to C++ standard streams block and there is no way to interrupt a blocking call, at least not in a portable way).
The only way to simulate asynchronous I/O using blocking calls is to use a separate thread for every I/O object.
This doesn't work either as you can't interrupt the blocking call if you want to close the stream. Boris

Boris wrote:
On Mon, 07 Apr 2008 11:40:48 +0200, Sebastian Redl <sebastian.redl@getdesigned.at> wrote:
The only way to simulate asynchronous I/O using blocking calls is to use a separate thread for every I/O object.
This doesn't work either as you can't interrupt the blocking call if you want to close the stream.
You can kill the thread. Not exactly portable, and will probably leak resources, though. Sebastian

----Original Message---- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Sebastian Redl Sent: 07 April 2008 14:23 To: boost@lists.boost.org Subject: Re: [boost] Asynchronous Boost.Iostreams with Boost.Asio
Boris wrote:
On Mon, 07 Apr 2008 11:40:48 +0200, Sebastian Redl <sebastian.redl@getdesigned.at> wrote:
The only way to simulate asynchronous I/O using blocking calls is to use a separate thread for every I/O object.
This doesn't work either as you can't interrupt the blocking call if you want to close the stream.
You can kill the thread. Not exactly portable, and will probably leak resources, though.
Not a good plan. We have recently run into a problem where our application would not shut down because a library had used TerminateThread to (ahem) terminate a thread. The thread had been holding a Critical Section (Win32 within-process-only mutex), and when some other thread tried to acquire the critical section there was a rather long wait for the terminated thread to release it. It is extremely difficult to know what resources IOStreams will use internally, but protecting access via a critical section seems entirely plausible. -- Martin Bonner Senior Software Engineer/Team Leader PI SHURLOK LTD Telephone: +44 1223 441434 / 203894 (direct) Fax: +44 1223 203999 Email: martin.bonner@pi-shurlok.com www.pi-shurlok.com disclaimer

On Mon, 07 Apr 2008 11:40:48 +0200, Sebastian Redl <sebastian.redl@getdesigned.at> wrote:
Boris wrote:
I ask as I was trying to extend Boost.Asio and add support for C++ standard streams on the weekend. I came to the conclusion that C++ this is impossible (as calls to C++ standard streams block and there is no way to interrupt a blocking call, at least not in a portable way).
The only way to simulate asynchronous I/O using blocking calls is to use a separate thread for every I/O object.
This doesn't work either as you can't interrupt the blocking call if you want to close the stream.
Two ways: 1.) use asynchronous I/O with aio-system calls (UNIX: aio_read/aio_write, ... whith aiocb struct; AFAIK not supported by boost::asio) Note: AIO is not supported on all systems (for instance on LINUX aio doesn't realy support sockets) and other I/O techniques maybe faster and more efficient. 2.) use synchronous I/O with non-blocking descriptors, demultiplexing techniques (select, epoll, kqueue,...) and threads (==the way boost::asio works). regards, Oliver

On Tue, 08 Apr 2008 08:43:52 +0200, Kowalke Oliver (QD IT PA AS) <Oliver.Kowalke@qimonda.com> wrote:
[...]Two ways:
1.) use asynchronous I/O with aio-system calls (UNIX: aio_read/aio_write, ... whith aiocb struct; AFAIK not supported by boost::asio) Note: AIO is not supported on all systems (for instance on LINUX aio doesn't realy support sockets) and other I/O techniques maybe faster and more efficient.
2.) use synchronous I/O with non-blocking descriptors, demultiplexing techniques (select, epoll, kqueue,...) and threads (==the way boost::asio works).
Well, this wouldn't be a C++ library then to make C++ standard streams support asynchronous I/O. It would rather be a system-specific library where C++ developers would have to find out themselves if their streams are represented by something platform-specific like file descriptors. Boris
participants (4)
-
Boris
-
Kowalke Oliver (QD IT PA AS)
-
Martin Bonner
-
Sebastian Redl