Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the use of asio::placeholder::error

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.

like image 996
kvanbere Avatar asked Apr 07 '13 06:04

kvanbere


1 Answers

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.

like image 168
Igor R. Avatar answered Oct 05 '22 17:10

Igor R.