Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::asio::asyn_accept handler
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2017-03-29 14:37:14


AMDG

On 03/29/2017 07:41 AM, Christopher Pisz via Boost-users wrote:
> So, your whole method looks like:
>
> void start_accept()
> {
> tcp_connection::pointer new_connection =
> tcp_connection::create(acceptor_.get_io_service());
>
> std::function<void(const boost::system::error_code &error)>
> callback = std::bind(&tcp_server::handle_accept, this, new_connection,
> std::placeholders::_1);
>
> acceptor_.async_accept(new_connection->socket(), callback);
> }
>
> Seems to compile.
>
> I really don't understand how we are binding arguments that the template
> parameters did not specify the std::function to take.
> Can I pass it a cow or a moose too and it won't care? As long as the
> callback takes a cow and a moose?
>

  Exactly. The error_code is passed as _1. All
the other arguments are saved by std::bind and
std::function doesn't need to know about them
at all.

> I thought all arguments had to be specified in the template params.
>

  All the arguments that are passed to the std::function
need to be specified. async_accept ends up calling
'callback' with just an error_code.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net