"gipsy boy" <x@x.pi> wrote in message
news:Ep*********************@phobos.telenet-ops.be...
Given a file descriptor (from a network socket, for instance), I want to
have an iostream that reads/writes to it, so I can push and read data in
the traditional way :
sockStream << "<some stuff>" < "\r\n"
How is this possible with the standard header files?
I need this because my objects have xml'ed << operators, but now I can't
figure out how to use them on the actual network stream.
I suppose I'll have to use a temporary file then? Just thought it'd be
possible in one go..
Thanks,
If the file descriptor is opened in blocking mode, you can use the file
descriptor resources from the Boost Iostreams Library:
http://home.comcast.net/~jturkanis/i.../?path=5.9.1.3.
Sample usage:
using namespace boost::io;
typedef stream_facade<file_descriptor_sink> fdostream;
int fd = ...;
fdostream out(fd);
out << "Hello, World!"; // writes to file descriptor fd.
This library will appear (slightly modified) in the next release of Boost
(1.33). It is available for download here
http://home.comcast.net/~jturkanis/iostreams/
Best Regards,
Jonathan