From f22e91b9ed224687ee72b77fbef9519faee3a176 Mon Sep 17 00:00:00 2001 From: Vitaly Petrov Date: Thu, 12 Sep 2019 19:39:17 +0300 Subject: [PATCH] Add moveToThread support --- core/conptyprocess.cpp | 5 +++++ core/conptyprocess.h | 1 + core/iptyprocess.h | 1 + core/unixptyprocess.cpp | 5 +++++ core/unixptyprocess.h | 1 + core/winptyprocess.cpp | 6 ++++++ core/winptyprocess.h | 1 + 7 files changed, 20 insertions(+) diff --git a/core/conptyprocess.cpp b/core/conptyprocess.cpp index 384b37f..009de1a 100644 --- a/core/conptyprocess.cpp +++ b/core/conptyprocess.cpp @@ -306,3 +306,8 @@ bool ConPtyProcess::isAvailable() return false; return m_winContext.init(); } + +void ConPtyProcess::moveToThread(QThread *targetThread) +{ + //nothing for now... +} diff --git a/core/conptyprocess.h b/core/conptyprocess.h index 365d351..c684ae1 100644 --- a/core/conptyprocess.h +++ b/core/conptyprocess.h @@ -140,6 +140,7 @@ public: virtual QByteArray readAll(); virtual qint64 write(const QByteArray &byteArray); bool isAvailable(); + void moveToThread(QThread *targetThread); private: HRESULT createPseudoConsoleAndPipes(HPCON* phPC, HANDLE* phPipeIn, HANDLE* phPipeOut, qint16 cols, qint16 rows); diff --git a/core/iptyprocess.h b/core/iptyprocess.h index 338815a..07fff01 100644 --- a/core/iptyprocess.h +++ b/core/iptyprocess.h @@ -36,6 +36,7 @@ public: virtual QByteArray readAll() = 0; virtual qint64 write(const QByteArray &byteArray) = 0; virtual bool isAvailable() = 0; + virtual void moveToThread(QThread *targetThread) = 0; qint64 pid() { return m_pid; } QPair size() { return m_size; } const QString lastError() { return m_lastError; } diff --git a/core/unixptyprocess.cpp b/core/unixptyprocess.cpp index 67ded53..9849e46 100644 --- a/core/unixptyprocess.cpp +++ b/core/unixptyprocess.cpp @@ -156,6 +156,7 @@ bool UnixPtyProcess::startProcess(const QString &shellPath, QStringList environm m_readMasterNotify = new QSocketNotifier(m_shellProcess.m_handleMaster, QSocketNotifier::Read, &m_shellProcess); m_readMasterNotify->setEnabled(true); + m_readMasterNotify->moveToThread(m_shellProcess.thread()); QObject::connect(m_readMasterNotify, &QSocketNotifier::activated, [this](int socket) { Q_UNUSED(socket) @@ -314,6 +315,10 @@ bool UnixPtyProcess::isAvailable() return true; } +void UnixPtyProcess::moveToThread(QThread *targetThread) +{ + m_shellProcess.moveToThread(targetThread); +} void ShellProcess::setupChildProcess() { diff --git a/core/unixptyprocess.h b/core/unixptyprocess.h index 67316f7..ce419ab 100644 --- a/core/unixptyprocess.h +++ b/core/unixptyprocess.h @@ -46,6 +46,7 @@ public: virtual QByteArray readAll(); virtual qint64 write(const QByteArray &byteArray); virtual bool isAvailable(); + void moveToThread(QThread *targetThread); private: ShellProcess m_shellProcess; diff --git a/core/winptyprocess.cpp b/core/winptyprocess.cpp index c07f968..1990d6c 100644 --- a/core/winptyprocess.cpp +++ b/core/winptyprocess.cpp @@ -221,3 +221,9 @@ bool WinPtyProcess::isAvailable() #endif } + +void WinPtyProcess::moveToThread(QThread *targetThread) +{ + m_inSocket.moveToThread(targetThread); + m_outSocket.moveToThread(targetThread); +} diff --git a/core/winptyprocess.h b/core/winptyprocess.h index 7fea5e8..a98e977 100644 --- a/core/winptyprocess.h +++ b/core/winptyprocess.h @@ -19,6 +19,7 @@ public: QByteArray readAll(); qint64 write(const QByteArray &byteArray); bool isAvailable(); + void moveToThread(QThread *targetThread); private: winpty_t *m_ptyHandler;