27 Jul
2011
27 Jul
'11
8:16 a.m.
I found this example for use the async_accept() method:
void accept_handler(const boost::system::error_code& error) { if (!error) { // Accept succeeded. } }
...
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::socket socket(io_service); acceptor.async_accept(socket, accept_handler);
It is possible use the async_accept with a (c++0x) lambda function instead of the function accept_handler()?
Sure, you can. ...async_accept(socket, [=] (const boost::system::error_code &error) {doSomething();}); Or, in a more readable form: auto handler = [=] (const boost::system::error_code &error) { doSomething(); }; ...async_accept(socket, handler);