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

时光怂恿深爱的人放手 提交于 2019-12-22 03:48:48

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/15859605/whats-the-use-of-asioplaceholdererror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!