@@ -73,12 +73,18 @@ CTcpConnection::CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcp
7373 connect ( pTcpSocket, &QTcpSocket::readyRead, this , &CTcpConnection::OnReadyRead );
7474
7575 connect ( this , &CTcpConnection::ProtocolCLMessageReceived, pServer, &CServer::OnProtocolCLMessageReceived );
76+
77+ // setup an idle timer on the server side only
78+ connect ( &TimerIdleTimeout, &QTimer::timeout, this , &CTcpConnection::OnTimerIdleTimeout );
79+ TimerIdleTimeout.setSingleShot ( true );
80+ TimerIdleTimeout.start ( TCP_IDLE_TIMEOUT_MS );
7681}
7782
7883void CTcpConnection::OnDisconnected ()
7984{
8085 qDebug () << " - Jamulus-TCP: disconnected from:" << tcpAddress.toString ();
8186 TimerKeepalive.stop ();
87+ TimerIdleTimeout.stop ();
8288 pTcpSocket->deleteLater ();
8389 if ( pChannel && pChannel->GetTcpConnection () == this )
8490 {
@@ -183,6 +189,12 @@ void CTcpConnection::OnReadyRead()
183189 }
184190
185191 qDebug () << " - end of readyRead(), bytesAvailable() =" << pTcpSocket->bytesAvailable ();
192+
193+ if ( pServer )
194+ {
195+ // restart server idle timer allowing for keepalive interval
196+ TimerIdleTimeout.start ( TCP_KEEPALIVE_INTERVAL_MS + TCP_IDLE_TIMEOUT_MS );
197+ }
186198}
187199
188200void CTcpConnection::OnTimerKeepalive ()
@@ -191,6 +203,12 @@ void CTcpConnection::OnTimerKeepalive()
191203 emit CLSendEmptyMes ( tcpAddress, this );
192204}
193205
206+ void CTcpConnection::OnTimerIdleTimeout ()
207+ {
208+ // qDebug() << "- ConnTimeout timer" << this << "from TCP" << tcpAddress.toString();
209+ disconnectFromHost ();
210+ }
211+
194212qint64 CTcpConnection::write ( const char * data, qint64 maxSize )
195213{
196214 if ( !pTcpSocket )
0 commit comments