You should check if the ioservice has enough threads to handle more than one client, maybe you have a single thread being blocked by the call to
session->start(), if this is the case, your server cannot accept another client until the thread is released (make sure the ioservice has an oioservice::work object attached, btw).
On Fri, Jan 4, 2013 at 2:30 PM, Gonzalo Garramuno
<ggarra13@gmail.com> wrote:
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
_______________________________________________