Boost logo

Boost :

From: Hamish Mackenzie (hamish_at_[hidden])
Date: 2002-11-24 20:42:50


On Sun, 2002-11-24 at 23:33, Boris Schäling wrote:
> > -----Original Message-----
> > From: boost-bounces_at_[hidden]
> > [mailto:boost-bounces_at_[hidden]]On Behalf Of Boris Schäling
> > Sent: Sunday, November 24, 2002 1:06 AM
> > To: Boost mailing list
> > Subject: RE: [boost] Re: AW: Re: AW: Sockets
>
> > [...]
> > I will try to set up another page at Boost Wiki to explain in
> > detail what I mean by multiplexing library.
>
> I added
> http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?BoostSocket/M
> ultiplexing to propose a design to support multiplexing. I am thankful for
> any comments as I use this kind of library already and would be happy to
> improve it.

Looks good but am I correct in thinking it uses blocking writes to the
socket? (no on_write). This is ok for some applications but would not
work for sending large files or streaming live content.

How about instead of using on_read (and on_write) we use C++ iostream to
process the data read from the socket and to produce the output to write
to the socket.

template< typename Char_Type, Traits = std::char_traits< Char_Type > >
class basic_observer
{
public:
    virtual std::basic_ostream< Char_Type, Traits > & read_stream();
    virtual std::basic_istream< Char_Type, Traits > & write_stream();
...
};

typedef basic_observer observer;

It seems a bit odd at first (read_stream is an ostream). But the idea
is that read_stream and write_stream would return non blocking streams
(or at least streams less likely to block than the socket)

In your first example instead of

void on_read( connection *, int count )...

You would have
        
std::ostream & read_stream() { return std::cout; }

Instead of calling on_read the internal library code would call

o.read_stream().write( data, length );

The only hassle is that deriving a streambuf can be a little bit
daunting but I think this is small price to pay. The big payoff is with
filter streams as you can use them in blocking and nonblocking socket
IO.

Often you need a full set filters though. For example to read and write
zip files you may just have o_zip_filter and i_unzip_filter.

Using the non blocking io these would allow you to compress data read
from the socket and write uncompressed data to the stream easily from a
zipped source. But if you want to receive a zip file you will need
o_unzip_filter and if you want to write something zipped you will need
i_zip_filter.

-- 
Hamish Mackenzie <hamish_at_[hidden]>

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