Boost logo

Boost Users :

Subject: Re: [Boost-users] ASIO async_accept() and c++2011 lambas
From: Andrew Holden (aholden_at_[hidden])
Date: 2011-07-27 09:39:01


On Wednesday, July 27, 2011 5:19 AM, Claude wrote:
> But it is possible to use the "error" variable outside the lambda
functions?
>
> I would like to get something like this:
>
> async_accept(socket, [=] (const boost::system::error_code &error)
> { // });
>
> if (!error)
> {
> //here there are a valid connection
> }

I'm not sure this can be made to do what you want. When async_accept
returns, you do NOT have a valid connection. The connection will
actually be accepted long after async_accept returns. By "long after",
I mean any time span from milliseconds to weeks. You truly want to test
the "error" variable inside the lambda because it is highly likely that
whatever function originally called async_accept has already returned
and gone out of scope.


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