Re: [asio-users] thread-safe async_write with streambuf
Brought to you by:
chris_kohlhoff
From: Daniel C. <dan...@gm...> - 2009-06-11 01:25:52
|
On Wed, Jun 10, 2009 at 5:01 PM, Scott Gifford<sgi...@su...> wrote: > Derek Taylor <dt...@da...> writes: > I implemented something very similar, and found that it worked > reliably and performance was fine. Asio can actually write a whole > vector of buffers at once, so I simply kept a vector of buffers > waiting to be written, and when I flushed the write buffer I would ask > asio to send the entire vector, then start working in a new vector. You can also use a pair of asio::streambuf objects to double buffer your sends. Copy the data into one of the streambufs while the other is being flushed to the network. Additionally, it gives you a convenient place to serialize the data before transmission. -- ~Dan |