Boost logo

Boost :

From: Boris Schäling (boris_at_[hidden])
Date: 2002-11-26 12:12:29


> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]]On Behalf Of Hamish Mackenzie
> Sent: Tuesday, November 26, 2002 1:34 AM
> To: Boost mailing list
> Subject: RE: [boost] Re: AW: Re: AW: Sockets
>
>
> On Mon, 2002-11-25 at 23:56, Boris Schäling wrote:
> > > This looks like a blocking write to me. What if there was not enough
> > > room in the buffer for this writen (say I wanted to do an HTTP post
> > > including a 5GB file as the post data). You need an on_write
> member to
> > > let you know when it is ok to do another write to the socket.
> >
> > stream::writen() calls ::write() to send the data to the network. If
> > EWOULDBLOCK is returned the stream notifies the multiplexor to
> watch out for
> > the socket descriptor to become writeable. Whenever that happens the
> > multiplexor calls stream::write() (this one is different from
> > stream::writen()) which calls ::write() again. Your proposed
> on_write() and
> > the buffer exist in stream. Advantage: No action needs to be
> taken by the
> > application developer.
>
> How does the multiplexor know what to pass to write the second time?

The multiplexor doesn't know but the stream does. The multiplexor calls
stream::write() when the socket descriptor is writable. The stream calls
::write() and sends all data which was saved in the stream's buffer because
of EWOULDBLOCK to the network.

+-------------+ +--------------+ 1) +--------------+
| multiplexor | 2) | stream |<-------| observer |
| |<-------| | | |
| | 3) | | | |
| |------->| | | |
+-------------+ +--------------+ +--------------+

1) observer calls stream::writen() to send data.
2) stream calls multiplexor::set_write() because of EWOULDBLOCK.
3) multiplexor calls stream::write() when the socket descriptor is writable.

> Does the caller have to load the 5GB file into memory before passing it
> to the write?

The caller may certainly write the file in chunks. Or did I misunderstand
your question?

> What if I want to send a live video stream?

Good point. There is currently no UDP support in my library. Maybe traits
could be used to tell the stream to discard data that couldn't be written
immediately? I am not sure if anything else had to be changed for UDP?

Boris


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