Boost logo

Boost Users :

From: Jonathan Turkanis (turkanis_at_[hidden])
Date: 2008-01-18 17:48:37


Eric MALENFANT wrote:
> Rob Desbois, le 18 janvier 2008 08:02:
>> After trying to compile I realised that a SeekableDevice
>> provides read, write and seek functions, nothing else.
>> Am I seriously misunderstanding the point of boost::iostreams?

> A file_descriptor only implements the Device concept, it not
> an std::iostream. If you want an std::iostream, you wrap the Device
> in a boost::iostreams::stream which, as stated in its documentation:
> "performs i/o by delegating to a contained Device", and "derives from
> a specialization of std::basic_istream, std::basic_ostream or
> std::basic_iostream, depending on whether the underlying Device
> models Source, Sink or both."
>

Right. What you probably need to do is define your own device,
SerialPort, which would not be a seekable device; instead, it might be a
bidirectional device
(http://www.boost.org/libs/iostreams/doc/index.html?path=4.1.1.1).

I must warn you in advance, however, that the C++ standard library
iostream abstractions only works well for blocking I/O. I have a feeling
that access to a serial port might be non-blocking, i.e., that a read or
write might fail to process the requested number of character even
though no error has occurred and EOF has not been reached. (See the
brief discussions here
(http://www.boost.org/libs/iostreams/doc/index.html?path=4.1.1.1) and
here (http://tinyurl.com/yoqrw5))

It has been on my todo list for some time to add to Boost.Iostreams some
abstractions that will be useful with non-blocking devices, but I
haven't done it yet.

-- 
Jonathan Turkanis
CodeRage
http://www.coderage.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net