Do not emit readyRead() recursively on close notification
QAbstractSocket already prevents from the recursive readyRead() emission in canReadNotification(). Follow this behavior in case the socket receives a close notification. Change-Id: Ifd916d60252832c19e0dcdeaa8dde8af75b45cf7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
14960f5227
commit
25c0fdc885
|
|
@ -723,7 +723,7 @@ bool QAbstractSocketPrivate::canReadNotification()
|
|||
}
|
||||
}
|
||||
|
||||
// only emit readyRead() when not recursing, and only if there is data available
|
||||
// Only emit readyRead() if there is data available.
|
||||
bool hasData = newBytes > 0
|
||||
#ifndef QT_NO_UDPSOCKET
|
||||
|| (!isBuffered && socketType != QAbstractSocket::TcpSocket && socketEngine && socketEngine->hasPendingDatagrams())
|
||||
|
|
@ -731,11 +731,8 @@ bool QAbstractSocketPrivate::canReadNotification()
|
|||
|| (!isBuffered && socketType == QAbstractSocket::TcpSocket && socketEngine)
|
||||
;
|
||||
|
||||
if (!emittedReadyRead && hasData) {
|
||||
QScopedValueRollback<bool> r(emittedReadyRead);
|
||||
emittedReadyRead = true;
|
||||
emit q->readyRead();
|
||||
}
|
||||
if (hasData)
|
||||
emitReadyRead();
|
||||
|
||||
// If we were closed as a result of the readyRead() signal,
|
||||
// return.
|
||||
|
|
@ -794,12 +791,12 @@ void QAbstractSocketPrivate::canCloseNotification()
|
|||
// then occur when we read from the socket again and fail
|
||||
// in canReadNotification or by the manually created
|
||||
// closeNotification below.
|
||||
emit q->readyRead();
|
||||
emitReadyRead();
|
||||
|
||||
QMetaObject::invokeMethod(socketEngine, "closeNotification", Qt::QueuedConnection);
|
||||
}
|
||||
} else if (socketType == QAbstractSocket::TcpSocket && socketEngine) {
|
||||
emit q->readyRead();
|
||||
emitReadyRead();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1305,6 +1302,21 @@ bool QAbstractSocketPrivate::readFromSocket()
|
|||
return true;
|
||||
}
|
||||
|
||||
/*! \internal
|
||||
|
||||
Prevents from the recursive readyRead() emission.
|
||||
*/
|
||||
void QAbstractSocketPrivate::emitReadyRead()
|
||||
{
|
||||
Q_Q(QAbstractSocket);
|
||||
// Only emit readyRead() when not recursing.
|
||||
if (!emittedReadyRead) {
|
||||
QScopedValueRollback<bool> r(emittedReadyRead);
|
||||
emittedReadyRead = true;
|
||||
emit q->readyRead();
|
||||
}
|
||||
}
|
||||
|
||||
/*! \internal
|
||||
|
||||
Sets up the internal state after the connection has succeeded.
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ public:
|
|||
void fetchConnectionParameters();
|
||||
void setupSocketNotifiers();
|
||||
bool readFromSocket();
|
||||
void emitReadyRead();
|
||||
|
||||
qint64 readBufferMaxSize;
|
||||
QRingBuffer writeBuffer;
|
||||
|
|
|
|||
Loading…
Reference in New Issue