Skip to content

Commit

Permalink
Add QProcess check in msgpackiodevice dtor
Browse files Browse the repository at this point in the history
This uses a dynamic cast for casting this to a QProcess and calls
QProcess::terminate() to try and softly shut it down, waiting at most
100ms for the process.
  • Loading branch information
equalsraf committed Jul 29, 2023
1 parent e16ce98 commit 363b434
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/msgpackiodevice.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <QAbstractSocket>
#include <QSocketNotifier>
#include <QProcess>

// read/write
#ifdef _WIN32
Expand Down Expand Up @@ -72,6 +73,16 @@ MsgpackIODevice::~MsgpackIODevice()
{
//msgpack_packer_destroy(&m_pk);
msgpack_unpacker_destroy(&m_uk);

// If the device is backed by a QProcess then the QProcess dtor will
// be used, but its default behaviour is too aggressive (SIGKILL). Try
// to softly bring it down here first.
QProcess* p = qobject_cast<QProcess*>(m_dev);
if (p) {
p->terminate();
bool fin = p->waitForFinished(100);
qDebug() << "Terminating QProcess device" << fin;
}
}

bool MsgpackIODevice::isOpen()
Expand Down

0 comments on commit 363b434

Please sign in to comment.