It's fine to call start_accept() inside the handle_accept() function, if you don't do it your server will not be able to accept another client
My problem was that acceptor_ was called twice and two sessions were created. The first session was used properly while the second session missed the socket setup.
class server
{
public:
server(boost::asio::io_service& io_service,
const tcp::endpoint& listen_endpoint,
mrv::ViewerUI* v)
: io_service_(io_service),
acceptor_(io_service, listen_endpoint),
ui_( v )
{
start_accept();
}
void start_accept()
{
tcp_session_ptr new_session(
boost::make_shared<tcp_session>(
boost::ref(
io_service_
),
boost::ref(ui_)
)
);
std::cerr << "******** TCP SESSION " << new_session << std::endl;
acceptor_.async_accept(new_session->socket(),
boost::bind(&server::handle_accept, this,
new_session, _1));
}
void handle_accept(tcp_session_ptr session,
const boost::system::error_code& ec)
{
if (!ec)
{
session->start();
}
start_accept(); // BAD
}
Changed to:
void handle_accept(tcp_session_ptr session,
const boost::system::error_code& ec)
{
if (!ec)
{
session->start();
}
else
{
start_accept();
}
}
I still don't know why this is so and the problem is not fully resolved, as only the server change in the timeline works only once, but at least the server now works.
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users