Fix Trk error handling

Do not close a trk device from its read handler, wire messages
correctly. TrkDevice: Terminate threads before closing.
This commit is contained in:
Friedemann Kleint
2009-10-05 15:07:47 +02:00
parent db9a390ef6
commit d38f654d53
5 changed files with 48 additions and 22 deletions

View File

@@ -836,6 +836,8 @@ TrkDevice::~TrkDevice()
bool TrkDevice::open(const QString &port, QString *errorMessage)
{
if (d->verbose)
qDebug() << "Opening" << port << "is open: " << isOpen();
close();
#ifdef Q_OS_WIN
d->deviceContext->device = CreateFile(port.toStdWString().c_str(),
@@ -908,6 +910,8 @@ void TrkDevice::close()
{
if (!isOpen())
return;
d->readerThread->terminate();
d->writerThread->terminate();
#ifdef Q_OS_WIN
CloseHandle(d->deviceContext->device);
d->deviceContext->device = INVALID_HANDLE_VALUE;
@@ -917,8 +921,6 @@ void TrkDevice::close()
#else
d->deviceContext->file.close();
#endif
d->readerThread->terminate();
d->writerThread->terminate();
if (d->verbose)
emitLogMessage("Close");
}