Boost logo

Boost Users :

From: Christopher Kohlhoff (chris_at_[hidden])
Date: 2006-10-24 17:28:56


Hi George,

george wrote:
> I start using asio in my project and I don't know how to reuse
> a socket... some code:
[code snipped]
> when I send the first request everything is ok but when I try
> for a second one I never get a reply or an error from the
> server...

It's hard to say why that would be the case without seeing the
real program, but judging by your next paragraph it's more to do
with the design approach you've taken.

> The easy way would be to have a thread/connection model so I
> could block each thread waiting to a socket but I want to use
> a thread-pool for my server so I want to know if there is any
> callback parameter I could pass to my socket and when there is
> data availiable in the socket the asio would fire the callback
> function .

Yes you could use a thread-per-connection design, but I wouldn't
recommend it :) Instead, I suggest you use the async_* functions
to have the reads and writes performed asynchronously. These
functions take a callback which is called after the asynchronous
operation completes. If you work through the daytime tutorial
programs you will see how this approach compares to the
"iterative" design you have now.

Cheers,
Chris


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