C++ disconnect sequence incorrect?

Post here your questions about the C++ API for SFS2X

Moderators: Lapo, Bax, MBagnati

dhuang11
Posts: 38
Joined: 02 May 2014, 08:21

C++ disconnect sequence incorrect?

Postby dhuang11 » 06 Nov 2015, 11:33

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;
}
User avatar
Lapo
Site Admin
Posts: 20277
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: C++ disconnect sequence incorrect?

Postby Lapo » 09 Nov 2015, 10:08

Hi,
thanks for your feedback. We're going to take a look during the week and get back to you.

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
MBagnati
Posts: 125
Joined: 12 Feb 2013, 10:57

Re: C++ disconnect sequence incorrect?

Postby MBagnati » 12 Nov 2015, 06:34

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

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 4 guests