Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::asio::asyn_accept handler
From: Christopher Pisz (christopherpisz_at_[hidden])
Date: 2017-03-28 23:02:01


> In any case, this is completely different code from what you had in your
> previous post. I already showed you what to use for your previous code.

What you showed me in the previous code did not work, it did not compile. I
am trying to give a thorough complete minimal example, without the
complexity of my own classes.

>Now, have a look at the code you wrote:
>
> const std::function<void(tcp_connection::pointer, const
> boost::system::error_code&)> callback =
> std::bind(&tcp_server::handle_accept, this, new_connection,
> std::placeholders::_1);
>
> You are declaring a function that takes a tcp_connection::pointer and a
> const boost::system::error_code& as parameters -- that's two parameters.
> But you're only using one placeholder in the bind, which means that
> the second parameter doesn't go anywhere, which is probably not your
> intention.

Sigh. I know that code wouldn't work. That is my interpretation of what you
gave me. Now you are talking about two arguments and placeholders, but why
would I give it a place holder, when I am giving it the argument directly?
the tcp_connection::pointer argument is new_connection. The placeholder is
for the error code which I am not supplying directly. Either way, it still
fails to compile if you add a std::placeholders::_2 on the end.

Can we just get a compilable working example of the following method while
maintaining the use of the std::function variable? I don't want to bind
directly, I don't want to use lambda, I want to have an std::function
variable that I can pass to others. It's really a simple 6 line problem....

The following code still fails to compile:

    void start_accept()
    {
        tcp_connection::pointer new_connection =
            tcp_connection::create(acceptor_.get_io_service());

        std::function<void(tcp_connection::pointer new_connection, const
boost::system::error_code &amp; error)> callback =
            std::bind(&tcp_server::handle_accept, this, new_connection,
std::placeholders::_1);

        acceptor_.async_accept(new_connection->socket(), callback);
    }

--
View this message in context: http://boost.2283326.n4.nabble.com/boost-asio-asyn-accept-handler-tp4693107p4693169.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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