Boost logo

Boost Users :

Subject: Re: [Boost-users] ASIO async IO, will the buffer corrupt?
From: Rutger ter Borg (rutger_at_[hidden])
Date: 2010-05-21 05:55:56


Lloyd wrote:

> Hello,
> we are trying to write a high performane storage server. For that we are
> using Aynchronous IO with boost::asio. The data will be received at the
> storage server with the help of boost::asio::async_read(), and the data
> will be written to the storage with boost::asio::async_write() in the
> asyn_read() completion handler. Here we are planning to share the data
> buffer. The async read will be running in a loop, so if the write is not
> completed and if the next async_read() attempts to access the buffer,
> will the buffer be corrupted?

Yes.

>
> If we use seperate buffer for each async_read()+async_write() operation,
> wouldn't it be inefficient?
>

It's as efficient, it only takes more memory. What happens if the reads go
faster than the writes? It sounds like you use a typical producer/consumer
pattern and could use off-the-shelf solutions for that, like, e.g., a
circular buffer.

Cheers,

Rutger


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