Boost logo

Boost Users :

Subject: Re: [Boost-users] Problem finally found!
From: Juan Ramírez (juanantonio.ram_at_[hidden])
Date: 2013-01-05 21:55:38


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

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).

__________
Saludos!
     Juan

On Fri, Jan 4, 2013 at 2:30 PM, Gonzalo Garramuno <ggarra13_at_[hidden]>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_at_[hidden]
> http://lists.boost.org/**mailman/listinfo.cgi/boost-**users>
>



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