From 4cb16b105f5dbd7c2a0cbc703aab3e64359c99c8 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Wed, 22 Sep 2021 10:59:03 +0100 Subject: [PATCH] Add keepalive for linux/mac pty --- pttyhandler.cpp | 7 +++++++ pttyhandler.h | 1 + 2 files changed, 8 insertions(+) diff --git a/pttyhandler.cpp b/pttyhandler.cpp index 6b4350d..36a5204 100644 --- a/pttyhandler.cpp +++ b/pttyhandler.cpp @@ -73,6 +73,9 @@ void pttyHandler::openPort() // we're good! qInfo(logSerial()) << "Opened pseudoterminal, slave name :" << ptsname(ptfd); + // Open the slave device to keep alive. + ptKeepAlive = open(ptsnamd(ptfd), O_RDONLY); + ptReader = new QSocketNotifier(ptfd, QSocketNotifier::Read, this); connect(ptReader, &QSocketNotifier::activated, this, &pttyHandler::receiveDataIn); @@ -283,6 +286,10 @@ void pttyHandler::closePort() { QFile::remove(portName); } + + if (ptKeepAlive > 0) { + close(ptKeepAlive); + } #endif isConnected = false; } diff --git a/pttyhandler.h b/pttyhandler.h index 14c9bfc..73aa80e 100644 --- a/pttyhandler.h +++ b/pttyhandler.h @@ -62,6 +62,7 @@ private: bool rolledBack; int ptfd; // pseudo-terminal file desc. + int ptKeepAlive=0; // Used to keep the pty alive after client disconects. bool havePt; QString ptDevSlave;