Boost logo

Boost Users :

Subject: Re: [Boost-users] Using boost::asio::async_write to stream out data
From: Matheus Araújo Aguiar (matheus.pit_at_[hidden])
Date: 2009-07-17 13:47:36


Hello,

On Fri, Jul 17, 2009 at 2:13 PM, Alex Black <alex_at_[hidden]> wrote:

> My app writes out a large amount of data to a socket, in a loop, in
> pieces, say 8kb at a time.
>
> I'd like to switch from using Socket::send to use asio::async_write. At
> a high level, what do I need to do? From my reading, I think I need to:
>
> 1. Call async_write instead of send
>
> 2. Ensure that my buffers have the correct lifetime
> - today since my writes are synchronous I re-use the same buffer over
> and over again
> - so instead, should I make a new buffer for each write? Whats a good
> way to ensure the buffer has the correct lifetime, e.g. how do I delete
> it once its been written out?

Yes, you should have a new buffer (at least a buffer that's not being used
and will not be used untill the completion of the operation). You delete the
buffer (or set it for reuse, if it is the case), at the write callback which
is invoked when the async_write completes.

>
>
> 3. I understand I can't call async_write again before the first one has
> been completed (since I don't want my 8kb chunks interleaved), so should
> I maintain a queue of buffers waiting to go out?

>
> Then in my handle_write method should I check the queue, if at least one
> buffer is in the queue then I should start a new async_write?

Well, i don't know how to answer this one, and maybe that's the problem i'm
having right now with my tcp async write code, then i'm so confused as you.

>
>
> Thanks!
>
> - Alex
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Matheus Araújo Aguiar
Computer Scientist
matheus.pit_at_[hidden]


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