What's the use of asio::placeholder::error
Asked Answered
N

1

10

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.

Ninny answered 7/4, 2013 at 6:29 Comment(0)
D
14

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.

Drip answered 7/4, 2013 at 6:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.