Wireless Communication Library Support Forum
Frameworks => Bluetooth Framework => Topic started by: david_dcl on June 10, 2014, 06:52:23 AM
-
Hi,
Recently I added a call to CwclServer::Close() in the function that is hooked to the event CwclServer::OnDisconnected. This worked as expected on the Microsoft stacks, however on the Toshiba stack it causes a crash. I require this as I do not want to listen for inbound connections after the the remote side has disconnected.
This crash happens because CloseToshiba() gets called twice, and the second time it deletes the now NULL m_pSerialClient (which got deleted on the first call).
in the CwclCustomServerConnection::Close(), the third line "Disconnect()" triggers the callback, which in turn calls Close(), after which Close() continues and calls CloseTosiba() on an already closed stack.
adding
if (m_ToshibaState == tssClosed)
return;
to the top of CloseToshiba() fixed the problem.
Is calling Close() inside the disconnect event handler OK? and if not is there a another way to close (stop the server listening) when the client disconnects.
Please note that I will be away for the next few days, so may be slow to reply if you need more information about this issue
Regards
David
-
Hi,
Thnak you for your very detailed report about this issue. I have to check that out and fix it. Calling Close inside OnDisconnect should be possible so this is the bug which I must fix. Your solution (adding
if (m_ToshibaState == tssClosed)
return;
)
looks good as temporary solution.
-
Hi,
I did lot of tests with different devices (including simple CwclClient->CwclServer connection and cell phone->CwclOPPServer) and could not reproduce the issue. Can you send me any code snippet/test project which reproduces the issue?
-
Have emailed you some code,
Cheers
David
-
OK got it.
-
Just took a look on your code. Actualy it's a mistake in your code (not sure it can be called bug). You cann Server->Close inside OnConnect and OnDisconnect. When device connects to your server OnConnect fires. You call Close. OnDisconnect fires and you call Close once again.