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;