On 28/03/2017 08:56, Christopher Pisz wrote:
I am looking at the example source at http://www.boost.org/doc/libs/1_62_0/doc/html/boost_asio/tutorial/tutdaytime...
It passes their own connection class to the accept handler as an argument:
acceptor_.async_accept(new_connection->socket(), boost::bind(&tcp_server::handle_accept, this, new_connection, boost::asio::placeholders::error));
I tried to implement a class method that would do the same:
void ServerSocketASIO::Listen(boost::asio::ip::tcp::acceptor & acceptor, std::function
callback) { acceptor.async_accept(m_socket, callback); m_connectionState = LISTENING; } but when I compile, I get errors that say AcceptHandler type requirements not met
Your version is not the same.
Consider the bind call in the tutorial: it takes a method which accepts
three parameters and binds two of them, producing a functor that accepts
a single error_code argument, which is what is actually passed to
async_accept.
In your case you are trying to pass a function that takes two parameters
to async_accept, which is incompatible. (You're also not actually
providing any value for that first parameter.)
You either need to use bind() as the tutorial does to provide a value
for the function's first parameter, eg:
void ServerSocketASIO::Listen(boost::asio::ip::tcp::acceptor & acceptor,
const std::function