If you read carefully the boost asio documentation reference, you sould see that the buffer in write operations have to meet some requirements.
These requirements are commonly called concepts. For writing, the buffer should meet the ConstBufferSequence concept (see the reference documentation for further explanation) and for reading the buffer should meet the MutableBufferSequence concept.

Defining value type and const_iterator to the already defined boost::asio::const_buffer is not necessarry, you only need to provide something convertible to const_buffer.
You also have to define an iterator to your buffers in case your buffer is a Sequence of Buffer (say a vector of buffers).
In general, just keep your implementation a one buffer sequence and if you want to pass many of them to async_write just push them on a vector and pass the vector as the argument to async_write.

2010/7/11 Matteo Lanzi <matteo.lanzi@kaseya.com>

Just a quick look but i have a quick question,

 

Write method require as second param a buffer; te axample you suggested pass shared_const_buffer which does not implements any  interface.

I suppose the trick should be in these lines

 

  typedef boost::asio::const_buffer value_type;

  typedef const boost::asio::const_buffer* const_iterator;

 

but I don’t know why.

 Can you explain me the trick ?

 

Thanks

Matteo

 

From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of ecyrbe
Sent: sabato 10 luglio 2010 16:48
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] asio::async_write, how to delete data after

 

see the reference_counted example in the boost asio documentation. It's a good start to allow dynamic buffer allocation and auto deletion when your message is delivered...

2010/7/10 Matteo Lanzi <matteo.lanzi@kaseya.com>

Hi, I modified a little the echo server example and to build up a simple tcp server; basically what I do is:

 

-          Start the server in a thread

-          When a session is created I start  async read

-          If my session receive a signal I  write a data with async write function

-          Handle data written then start again async read ( otherwise the connection should be closed )

 

I have some specific functions which prepare packets and then invoke the write method

 

I would like to avoid static allocation of my buffer instead of dynamic one; for doing that I supposed to use shared_array<T>

I can’t do that because the boost::asio::buffer, required by the write method, doesn’t seem to accept smart pointer.

 

So my questions are:

-          Is there a common pattern to follow for preparing data and delete them after the delivery ?

-          Is it possible to use smart pointers with async_write ?

-          Is the async_write executed in another thread ? should I have concurrency problems if I would use an unique output buffer and clear it on the handle_write callback ?

 

Thanks

Matteo

 

 


_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

 


_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users