Boost logo

Boost Users :

Subject: [Boost-users] boost::asio::asyn_accept handler
From: Christopher Pisz (christopherpisz_at_[hidden])
Date: 2017-03-27 19:56:26


I am looking at the example source at
http://www.boost.org/doc/libs/1_62_0/doc/html/boost_asio/tutorial/tutdaytime3/src.html

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<void(ServerSocketASIO *, const boost::system::error_code
&amp;)> callback)
{
    acceptor.async_accept(m_socket, callback);
    m_connectionState = LISTENING;
}

but when I compile, I get errors that say AcceptHandler type requirements
not met

If I implement it this way:

void ServerSocketASIO::Listen(boost::asio::ip::tcp::acceptor & acceptor,
std::function<void(const boost::system::error_code &amp;)> callback)
{
    acceptor.async_accept(m_socket, callback);
    m_connectionState = LISTENING;
}

It compiles, but I would need the actual connection to put into a collection
of some kind, in order to keep track of connected clients.

The documentation I found at
http://www.boost.org/doc/libs/1_62_0/doc/html/boost_asio/reference/AcceptHandler.html

Only shows the accept callback with a boost::system::error_code argument.

So, my question is, is the example source wrong? and How do I pass my own
connection class to the callback?

--
View this message in context: http://boost.2283326.n4.nabble.com/boost-asio-asyn-accept-handler-tp4693107.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