summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2010-02-09 11:56:55 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-02-09 12:08:39 (GMT)
commitc034670d71247954eb918dfc84536ace02c33304 (patch)
tree34b479929af9ddcaa10b9df878215d2041c3ed42 /src/network
parent74d3ef60ac8dfa12c90442062307e0c4b2600d03 (diff)
downloadQt-c034670d71247954eb918dfc84536ace02c33304.zip
Qt-c034670d71247954eb918dfc84536ace02c33304.tar.gz
Qt-c034670d71247954eb918dfc84536ace02c33304.tar.bz2
QNAM HTTP: Improve parseStatus() of HTTP reply
Just read() instead us using peek() and bytesAvailable() Reviewed-by: Peter Hartmann
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qhttpnetworkreply.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index a5223d1..b411467 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -425,11 +425,19 @@ qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket)
{
qint64 bytes = 0;
char c;
+ qint64 haveRead = 0;
+
+ do {
+ haveRead = socket->read(&c, 1);
+ if (haveRead == -1)
+ return -1; // unexpected EOF
+ else if (haveRead == 0)
+ break; // read more later
+
+ bytes++;
- while (socket->bytesAvailable()) {
// allow both CRLF & LF (only) line endings
- if (socket->peek(&c, 1) == 1 && c == '\n') {
- bytes += socket->read(&c, 1); // read the "n"
+ if (c == '\n') {
// remove the CR at the end
if (fragment.endsWith('\r')) {
fragment.truncate(fragment.length()-1);
@@ -442,11 +450,6 @@ qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket)
}
break;
} else {
- c = 0;
- int haveRead = socket->read(&c, 1);
- if (haveRead == -1)
- return -1;
- bytes += haveRead;
fragment.append(c);
}
@@ -456,8 +459,7 @@ qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket)
fragment.clear();
return -1;
}
-
- }
+ } while (haveRead == 1);
return bytes;
}