If commands are buffered and not sent when the device is disconnected, call any completion callbacks.

This is to guarantee that completion callbacks are always called, so if any
resource collection happens in them it'll always happen.
This commit is contained in:
Glenn Maynard 2018-11-08 16:07:45 -06:00
parent 135e3c5401
commit 4691ce5ecf

View File

@ -56,6 +56,19 @@ void SMX::SMXDeviceConnection::Close()
if(m_hDevice)
CancelIo(m_hDevice->value());
// If we're being closed while a command was in progress, call its completion
// callback, so it's guaranteed to always be called.
if(m_pCurrentCommand && m_pCurrentCommand->m_pComplete)
m_pCurrentCommand->m_pComplete();
// If any commands were queued with completion callbacks, call their completion
// callbacks.
for(auto &pendingCommand: m_aPendingCommands)
{
if(pendingCommand->m_pComplete)
pendingCommand->m_pComplete();
}
m_hDevice.reset();
m_sReadBuffers.clear();
m_aPendingCommands.clear();