title: boost asio sockets cant connect after stop
body: <p>Im using boost asio for implementing TCP sockets. I've followed the chat server example. The first time that I run the socket server it works ok. Im doing it like this:</p>
  
  <pre><code>     void ActiveSocketServer::run() throw (ActiveException){
  
       initBoost();
  
       server-&gt;startAccept();
  
       t=new boost::thread(boost::bind(&amp;boost::asio::io_service::run, &amp;io_service));
      }
  
      void ActiveSocketServer::initBoost(){
  
         if (isIpV6){
              endpoint=new tcp::endpoint(tcp::v6(), port);
         }else{
              endpoint=new tcp::endpoint(tcp::v4(), port);
         }
         server=new ActiveSocketServerConnection(io_service,
                      *endpoint,
                      port,
                      id,
                      maxSizePacket,
                      this);
  </code></pre>
  
  <p>}</p>
  
  <p>After start it, I call stop method, written like this:</p>
  
  <pre><code> void ActiveSocketServer::stop(){
       io_service.stop();
       if (t){
          t-&gt;join();
          delete t;
          t=NULL;
        }
  
        if (endpoint){
          delete endpoint;
          endpoint=NULL;
        }
  
        if (server){
           delete server;
           server=NULL;
        }
     }
  </code></pre>
  
  <p>And after this, the port is not up (netstat doesnt show). Later, I try to call run again and  any error is thrown, port is up (I can see with netstat) but any connections are accepted (async_accept is never waking up). </p>
  
  <p>I think that could be something about the io_service, but if make reset in stop method, and error 125 (operation cancelled) is thrown.</p>
  
  <p>Any idea?</p>
  
  <hr>
  
  <p>Yes, at the same moment that I call startAccept I'm receiving a new connection but with error 125. It is normal? where can I read something about it? </p>
  
  <p>My startAccept:</p>
  
  <pre><code>   void ActiveSocketServerConnection::startAccept(){
  
         sessionId++;
  
          newSession=new ActiveSocketServerSession(   io_service_,
                          getPort(),
                          getId(),
                          maxSizePacket,
                          activeSocketServer,
                          sessionId);
  
          acceptor_.async_accept( newSession-&gt;socket(),
                   boost::bind(&amp;ActiveSocketServerConnection::handleAccept, 
                           this, newSession,
                   boost::asio::placeholders::error));
          }
  </code></pre>
  
  <p>And the handle accept:</p>
  
  <pre><code>   void ActiveSocketServerConnection::handleAccept(ActiveSocketServerSession* newSession,
                                                            const boost::system::error_code&amp; error){
       if (!error){
         newSession-&gt;start();
  
           }else{
  
      activeSocketServer.onException(error);
  }
  </code></pre>