Question

The asio library passes an error parameter in a lot of its examples, ie; http://think-async.com/Asio/asio-1.5.3/src/examples/echo/async_tcp_echo_server.cpp

What's the point of this parameter? Does asio actually populate this parameter with errors?

If I remove it from my handler function it compiles fine.

Was it helpful?

Solution

Actually, asio::placeholders::error is equivalent to _1 Boost.Bind placeholder, so bind(&my_class::handler, this, asio::placeholders::error) is just like bind(&my_class::handler, this, _1).

When this handler is being called by Boost.Asio completion-handler dispatcher, error_code is passed as the 1st argument to this function.

However, you can always bind a function that expects less arguments (in this case - zero) - when the binder gets invoked, any extra arguments are silently ignored.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top