Boost logo

Boost Users :

Subject: [Boost-users] Problem finally found!
From: Gonzalo Garramuno (ggarra13_at_[hidden])
Date: 2013-01-04 11:30:53


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