|
Boost Users : |
Subject: [Boost-users] Handler requirement for Asynchronous Operations in boost::asio
From: Tu Hoang Do (solidius4747_at_[hidden])
Date: 2011-12-19 05:02:51
It is specified in
http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/reference/AcceptHandler.html
that a handler for `async_accept()` must satisfy the following function
signature:
void accept_handler(
const boost::system::error_code& ec)
{
...
}
However, in the `Daytime.3` example, using boost::bind, the handler can be
specified as much parameter as desired, as long as it does not exceed the
limit of `boost::bind` (which is 9 arguments at maximum):
class tcp_server
{
public:
tcp_server(boost::asio::io_service& io_service)
: acceptor_(io_service, tcp::endpoint(tcp::v4(), 13))
{
start_accept();
}
private:
void start_accept()
{
tcp_connection::pointer new_connection =
tcp_connection::create(acceptor_.get_io_service());
acceptor_.async_accept(new_connection->socket(),
boost::bind(&tcp_server::handle_accept, this, new_connection,
boost::asio::placeholders::error));
}
void handle_accept(tcp_connection::pointer new_connection,
const boost::system::error_code& error)
{
if (!error)
{
new_connection->start();
}
start_accept();
}
tcp::acceptor acceptor_;
};
Why is that possible? I thought even with `boost::bind`, the exact function
signature still has to be matched.
Notice the `handle_accept()` funciton and how it is used in
`async_accept()`. The full code listing is here:
http://www.boost.org/doc/libs/1_48_0/doc/html/boost_asio/tutorial/tutdaytime3/src.html
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