Page 1 of 1

C++ disconnect sequence incorrect?

Posted: 06 Nov 2015, 11:33
by dhuang11
Hi -

We're still seeing some crashes (a lot less than before) on iOS devices. When we disconnect from SmartFox, occasionally we'll get some crashes because SmartFox still attempts to read or write something back to the closed socket.

To try to alleviate this, we've used the same mechanism used elsewhere to allow the SmartFox socket to finish any "callbacksInProgress" before fully closing it down. We also added a call to shutdown the TCP socket as it seems that should be done first prior to closing it to avoid other data from coming in.

Can you take a look at the code snippet of changes we made below and let us know your thoughts on their feasibility?

Code: Select all


void TCPClient::Shutdown()
{
   // Cancel all asynchronous operations associated with the socket
    boostTcpSocket.shutdown(boost::asio::socket_base::shutdown_both);
    boostTcpSocket.close();
    //boostIoService.stop();
}

void TCPSocketLayer::Disconnect()
{
   if (State() != States_Connected)
   {
      boost::shared_ptr<string> message (new string("Calling disconnect when the socket is not connected"));
      LogWarn(message);   
      return;
   }

   isDisconnecting = true;
   
    while (this->connection->CallbackCallInProgress() == true)
    {
        boost::this_thread::sleep(boost::posix_time::milliseconds(100));
    }
         
   try
   {
      connection->Shutdown();
   }
   catch (...)
   {
   }

   HandleDisconnection();
   isDisconnecting = false;
}

void TCPSocketLayer::Kill()
{
   isDisconnecting = true;
         
    while (this->connection->CallbackCallInProgress() == true)
    {
        boost::this_thread::sleep(boost::posix_time::milliseconds(100));
    }
   
   try
   {
      connection->Shutdown();
   }
   catch (...)
   {
   }

   HandleDisconnection();
   isDisconnecting = false;
}

Re: C++ disconnect sequence incorrect?

Posted: 09 Nov 2015, 10:08
by Lapo
Hi,
thanks for your feedback. We're going to take a look during the week and get back to you.

cheers

Re: C++ disconnect sequence incorrect?

Posted: 12 Nov 2015, 06:34
by MBagnati
Hi,
thanks for your feedback.
I have read the suggested software changes and I think that they are good.
I will include these changes into the next API release.

Thanks again for your kind collaboration and your excellent work