diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2011-02-24 15:33:09 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2011-02-24 15:54:48 (GMT) |
commit | bb7d9bcc8e0c617091e91f7a40f3d33f8c1cdec1 (patch) | |
tree | 74eaeb955d5d2ef7c5eb31bbd0f871929d35b8cd /src/network | |
parent | 747a84637b88ce38697f031a1973b46d44af6099 (diff) | |
download | Qt-bb7d9bcc8e0c617091e91f7a40f3d33f8c1cdec1.zip Qt-bb7d9bcc8e0c617091e91f7a40f3d33f8c1cdec1.tar.gz Qt-bb7d9bcc8e0c617091e91f7a40f3d33f8c1cdec1.tar.bz2 |
QAbstractSocket: Check for engine validity on Unbuffered reads
Do not call read() if the socket engine is already invalid.
This could happen when using the Unbuffered QTcpSocket mode which
is currently only used inside QNetworkAccessManager.
Reviewed-by: Shane Kearns
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/socket/qabstractsocket.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 7c0dc11..e223358 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -2136,7 +2136,7 @@ qint64 QAbstractSocket::readData(char *data, qint64 maxSize) qDebug("QAbstractSocket::readData(%p '%c (0x%.2x)', 1) == 1 [char buffer]", data, isprint(int(uchar(*data))) ? *data : '?', *data); #endif - if (d->readBuffer.isEmpty() && d->socketEngine) + if (d->readBuffer.isEmpty() && d->socketEngine && d->socketEngine->isValid()) d->socketEngine->setReadNotificationEnabled(true); return 1; } @@ -2148,7 +2148,8 @@ qint64 QAbstractSocket::readData(char *data, qint64 maxSize) && d->readBuffer.size() < maxSize && d->readBufferMaxSize > 0 && maxSize < d->readBufferMaxSize - && d->socketEngine) { + && d->socketEngine + && d->socketEngine->isValid()) { // Our buffer is empty and a read() was requested for a byte amount that is smaller // than the readBufferMaxSize. This means that we should fill our buffer since we want // such small reads come from the buffer and not always go to the costly socket engine read() @@ -2198,6 +2199,8 @@ qint64 QAbstractSocket::readData(char *data, qint64 maxSize) if (!d->isBuffered) { if (!d->socketEngine) return -1; // no socket engine is probably EOF + if (!d->socketEngine->isValid()) + return -1; // This is for unbuffered TCP when we already had been disconnected qint64 readBytes = d->socketEngine->read(data, maxSize); if (readBytes == -2) { // -2 from the engine means no bytes available (EAGAIN) so read more later |