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.