void Protocol::__slotReadyRead() { #ifdef DEBUG_PROTOCOL qDebug() << this << "__slotReadyRead():" << socket->bytesAvailable() << "bytes available, restarting protocol timeout timer"; #endif restartProtocolTimeoutTimer(); }
void Protocol::__slotBytesWritten( qint64 /*bytes*/ ) { #ifdef DEBUG_PROTOCOL qDebug() << this << "__slotBytesWritten():" << bytes << "written, restarting protocol timeout timer"; #endif restartProtocolTimeoutTimer(); }
/* ======================================================================================================================= timeout restarts ======================================================================================================================= */ void Protocol::setTimeout( const int _timeout ) { #ifdef DEBUG_PROTOCOL qDebug() << this << "setTimeout():" << _timeout << "prev timeout was" << timeout; #endif if ( timeoutTimerId ) { #ifdef DEBUG_PROTOCOL qDebug() << this << "setTimeout(): stopping previous timer"; #endif killTimer( timeoutTimerId ); timeoutTimerId = 0; } if ( !(timeout > 0) && _timeout > 0 ) { /* * если предыдущий timeout НЕ был больше ноля, а текущий больше, * значит нужно прицепить сигналы приема/отсылки данных на сокете */ #ifdef DEBUG_PROTOCOL qDebug() << this << "setTimeout(): connect socket signals readyRead() and bytesWritten()"; #endif connect( socket, SIGNAL( readyRead()), this, SLOT( __slotReadyRead()) ); connect( socket, SIGNAL( bytesWritten( qint64)), this, SLOT( __slotBytesWritten( qint64)) ); } else if ( timeout > 0 && !(_timeout > 0) ) { /* новый выключен, старый был включен */ #ifdef DEBUG_PROTOCOL qDebug() << this << "setTimeout(): disconnect socket signals readyRead() and bytesWritten()"; #endif disconnect( socket, SIGNAL( readyRead()), this, SLOT( __slotReadyRead()) ); disconnect( socket, SIGNAL( bytesWritten( qint64)), this, SLOT( __slotBytesWritten( qint64)) ); } timeout= _timeout; if ( timeout > 0 ) restartProtocolTimeoutTimer(); }