ASIO async IO, will the buffer corrupt?

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? If we use seperate buffer for each async_read()+async_write() operation, wouldn't it be inefficient? Thanks, Lloyd ______________________________________ Scanned and protected by Email scanner

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

Thank you Rutger for suggesting the idea...
----- Original Message -----
From: "Rutger ter Borg"
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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
______________________________________ Scanned and protected by Email scanner
participants (2)
-
Lloyd
-
Rutger ter Borg