summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp8
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel.cpp34
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel_p.h2
-rw-r--r--src/network/access/qhttpnetworkheader.cpp2
-rw-r--r--src/network/access/qhttpnetworkreply.cpp68
-rw-r--r--src/network/access/qnetworkaccesshttpbackend.cpp2
-rw-r--r--src/network/access/qnetworkcookie.h2
-rw-r--r--src/network/access/qnetworkcookiejar.h2
-rw-r--r--src/network/access/qnetworkrequest.cpp2
-rw-r--r--src/network/kernel/qauthenticator.cpp4
-rw-r--r--src/network/kernel/qnetworkinterface.cpp4
-rw-r--r--src/network/socket/qlocalserver.cpp10
-rw-r--r--src/network/socket/qlocalsocket_tcp.cpp10
-rw-r--r--src/network/socket/qlocalsocket_unix.cpp14
-rw-r--r--src/network/socket/qtcpserver.cpp9
-rw-r--r--src/network/ssl/qsslcertificate.cpp4
-rw-r--r--src/network/ssl/qsslsocket.cpp2
-rw-r--r--src/network/ssl/qsslsocket_openssl.cpp2
18 files changed, 119 insertions, 62 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index fff7097..cc6a1c8 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -688,8 +688,14 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest()
if (channels[i].resendCurrent) {
channels[i].resendCurrent = false;
channels[i].state = QHttpNetworkConnectionChannel::IdleState;
- if (channels[i].reply)
+ if (channels[i].reply) {
+
+ // if this is not possible, error will be emitted and connection terminated
+ if (!channels[i].resetUploadData())
+ continue;
+
channels[i].sendRequest();
+ }
}
}
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
index b80ae9a..5bd972c 100644
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
@@ -305,9 +305,12 @@ void QHttpNetworkConnectionChannel::_q_receiveReply()
while (socket->bytesAvailable()) {
QHttpNetworkReplyPrivate::ReplyState state = reply ? reply->d_func()->state : QHttpNetworkReplyPrivate::AllDoneState;
switch (state) {
- case QHttpNetworkReplyPrivate::NothingDoneState:
- case QHttpNetworkReplyPrivate::ReadingStatusState: {
+ case QHttpNetworkReplyPrivate::NothingDoneState: {
+ // only eat whitespace on the first call
eatWhitespace();
+ state = reply->d_func()->state = QHttpNetworkReplyPrivate::ReadingStatusState;
+ }
+ case QHttpNetworkReplyPrivate::ReadingStatusState: {
qint64 statusBytes = reply->d_func()->readStatus(socket);
if (statusBytes == -1 && reconnectAttempts <= 0) {
// too many errors reading/receiving/parsing the status, close the socket and emit error
@@ -674,15 +677,8 @@ void QHttpNetworkConnectionChannel::handleStatus()
case 407: // proxy auth required
if (connection->d_func()->handleAuthenticateChallenge(socket, reply, (statusCode == 407), resend)) {
if (resend) {
- QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
- if (uploadByteDevice) {
- if (uploadByteDevice->reset()) {
- written = 0;
- } else {
- connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ContentReSendError);
- break;
- }
- }
+ if (!resetUploadData())
+ break;
reply->d_func()->eraseData();
@@ -712,6 +708,22 @@ void QHttpNetworkConnectionChannel::handleStatus()
}
}
+bool QHttpNetworkConnectionChannel::resetUploadData()
+{
+ QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
+ if (!uploadByteDevice)
+ return true;
+
+ if (uploadByteDevice->reset()) {
+ written = 0;
+ return true;
+ } else {
+ connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ContentReSendError);
+ return false;
+ }
+}
+
+
void QHttpNetworkConnectionChannel::pipelineInto(HttpMessagePair &pair)
{
// this is only called for simple GET
diff --git a/src/network/access/qhttpnetworkconnectionchannel_p.h b/src/network/access/qhttpnetworkconnectionchannel_p.h
index c30c236..75ab50d 100644
--- a/src/network/access/qhttpnetworkconnectionchannel_p.h
+++ b/src/network/access/qhttpnetworkconnectionchannel_p.h
@@ -151,6 +151,8 @@ public:
void allDone(); // reply header + body have been read
void handleStatus(); // called from allDone()
+ bool resetUploadData(); // return true if resetting worked or there is no upload data
+
void pipelineInto(HttpMessagePair &pair);
void requeueCurrentlyPipelinedRequests();
void detectPipeliningSupport();
diff --git a/src/network/access/qhttpnetworkheader.cpp b/src/network/access/qhttpnetworkheader.cpp
index c2cc69c..669f9cf 100644
--- a/src/network/access/qhttpnetworkheader.cpp
+++ b/src/network/access/qhttpnetworkheader.cpp
@@ -80,7 +80,7 @@ QByteArray QHttpNetworkHeaderPrivate::headerField(const QByteArray &name, const
QByteArray result;
bool first = true;
- foreach (QByteArray value, allValues) {
+ foreach (const QByteArray &value, allValues) {
if (!first)
result += ", ";
first = false;
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index a5223d1..512c045 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -423,13 +423,26 @@ int QHttpNetworkReplyPrivate::gunzipBodyPartially(QByteArray &compressed, QByteA
qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket)
{
+ if (fragment.isEmpty()) {
+ // reserve bytes for the status line. This is better than always append() which reallocs the byte array
+ fragment.reserve(32);
+ }
+
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 +455,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 +464,7 @@ qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket)
fragment.clear();
return -1;
}
-
- }
+ } while (haveRead == 1);
return bytes;
}
@@ -500,20 +507,41 @@ bool QHttpNetworkReplyPrivate::parseStatus(const QByteArray &status)
qint64 QHttpNetworkReplyPrivate::readHeader(QAbstractSocket *socket)
{
+ if (fragment.isEmpty()) {
+ // according to http://dev.opera.com/articles/view/mama-http-headers/ the average size of the header
+ // block is 381 bytes.
+ // reserve bytes. This is better than always append() which reallocs the byte array.
+ fragment.reserve(512);
+ }
+
qint64 bytes = 0;
char c = 0;
bool allHeaders = false;
- while (!allHeaders && socket->bytesAvailable()) {
- if (socket->peek(&c, 1) == 1 && c == '\n') {
- // check for possible header endings. As per HTTP rfc,
- // the header endings will be marked by CRLFCRLF. But
- // we will allow CRLFLF, LFLF & CRLFCRLF
- if (fragment.endsWith("\n\r") || fragment.endsWith('\n'))
- allHeaders = true;
+ qint64 haveRead = 0;
+ do {
+ haveRead = socket->read(&c, 1);
+ if (haveRead == 0) {
+ // read more later
+ break;
+ } else if (haveRead == -1) {
+ // connection broke down
+ return -1;
+ } else {
+ fragment.append(c);
+ bytes++;
+
+ if (c == '\n') {
+ // check for possible header endings. As per HTTP rfc,
+ // the header endings will be marked by CRLFCRLF. But
+ // we will allow CRLFCRLF, CRLFLF, LFLF
+ if (fragment.endsWith("\r\n\r\n")
+ || fragment.endsWith("\r\n\n")
+ || fragment.endsWith("\n\n"))
+ allHeaders = true;
+ }
}
- bytes += socket->read(&c, 1);
- fragment.append(c);
- }
+ } while (!allHeaders && haveRead > 0);
+
// we received all headers now parse them
if (allHeaders) {
parseHeader(fragment);
diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp
index 58123b2..61a95fe 100644
--- a/src/network/access/qnetworkaccesshttpbackend.cpp
+++ b/src/network/access/qnetworkaccesshttpbackend.cpp
@@ -753,7 +753,7 @@ void QNetworkAccessHttpBackend::replyHeaderChanged()
QByteArray value = rawHeader(it->first);
if (!value.isEmpty()) {
if (qstricmp(it->first.constData(), "set-cookie") == 0)
- value += "\n";
+ value += '\n';
else
value += ", ";
}
diff --git a/src/network/access/qnetworkcookie.h b/src/network/access/qnetworkcookie.h
index f34396f..3cc4cee 100644
--- a/src/network/access/qnetworkcookie.h
+++ b/src/network/access/qnetworkcookie.h
@@ -114,7 +114,7 @@ Q_NETWORK_EXPORT QDebug operator<<(QDebug, const QNetworkCookie &);
QT_END_NAMESPACE
// ### Qt5 remove this include
-#include "qnetworkcookiejar.h"
+#include <QtNetwork/QNetworkCookieJar>
Q_DECLARE_METATYPE(QNetworkCookie)
Q_DECLARE_METATYPE(QList<QNetworkCookie>)
diff --git a/src/network/access/qnetworkcookiejar.h b/src/network/access/qnetworkcookiejar.h
index 813bf3e..8086f38 100644
--- a/src/network/access/qnetworkcookiejar.h
+++ b/src/network/access/qnetworkcookiejar.h
@@ -46,7 +46,7 @@
#include <QtCore/QUrl>
// ### Qt5 remove this include
-#include "qnetworkcookie.h"
+#include <QtNetwork/QNetworkCookie>
QT_BEGIN_HEADER
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index 6dcd05d..a2bef67 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -649,7 +649,7 @@ static QVariant parseCookieHeader(const QByteArray &raw)
{
QList<QNetworkCookie> result;
QList<QByteArray> cookieList = raw.split(';');
- foreach (QByteArray cookie, cookieList) {
+ foreach (const QByteArray &cookie, cookieList) {
QList<QNetworkCookie> parsed = QNetworkCookie::parseCookies(cookie.trimmed());
if (parsed.count() != 1)
return QVariant(); // invalid Cookie: header
diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp
index 193a043..e4023c8 100644
--- a/src/network/kernel/qauthenticator.cpp
+++ b/src/network/kernel/qauthenticator.cpp
@@ -270,7 +270,7 @@ void QAuthenticatorPrivate::parseHttpResponse(const QHttpResponseHeader &header,
break;
case Ntlm:
// #### extract from header
- realm = QString();
+ realm.clear();
break;
case DigestMd5: {
realm = QString::fromLatin1(options.value("realm"));
@@ -281,7 +281,7 @@ void QAuthenticatorPrivate::parseHttpResponse(const QHttpResponseHeader &header,
break;
}
default:
- realm = QString();
+ realm.clear();
challenge = QByteArray();
phase = Invalid;
}
diff --git a/src/network/kernel/qnetworkinterface.cpp b/src/network/kernel/qnetworkinterface.cpp
index 367e3c4..1115c63 100644
--- a/src/network/kernel/qnetworkinterface.cpp
+++ b/src/network/kernel/qnetworkinterface.cpp
@@ -541,7 +541,7 @@ QList<QNetworkInterface> QNetworkInterface::allInterfaces()
{
QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();
QList<QNetworkInterface> result;
- foreach (QSharedDataPointer<QNetworkInterfacePrivate> p, privs) {
+ foreach (const QSharedDataPointer<QNetworkInterfacePrivate> &p, privs) {
QNetworkInterface item;
item.d = p;
result << item;
@@ -560,7 +560,7 @@ QList<QHostAddress> QNetworkInterface::allAddresses()
{
QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();
QList<QHostAddress> result;
- foreach (const QSharedDataPointer<QNetworkInterfacePrivate> p, privs) {
+ foreach (const QSharedDataPointer<QNetworkInterfacePrivate> &p, privs) {
foreach (const QNetworkAddressEntry &entry, p->addressEntries)
result += entry.ip();
}
diff --git a/src/network/socket/qlocalserver.cpp b/src/network/socket/qlocalserver.cpp
index ede3c89..ef7fc02 100644
--- a/src/network/socket/qlocalserver.cpp
+++ b/src/network/socket/qlocalserver.cpp
@@ -122,9 +122,9 @@ void QLocalServer::close()
qDeleteAll(d->pendingConnections);
d->pendingConnections.clear();
d->closeServer();
- d->serverName = QString();
- d->fullServerName = QString();
- d->errorString = QString();
+ d->serverName.clear();
+ d->fullServerName.clear();
+ d->errorString.clear();
d->error = QAbstractSocket::UnknownSocketError;
}
@@ -226,8 +226,8 @@ bool QLocalServer::listen(const QString &name)
}
if (!d->listen(name)) {
- d->serverName = QString();
- d->fullServerName = QString();
+ d->serverName.clear();
+ d->fullServerName.clear();
return false;
}
diff --git a/src/network/socket/qlocalsocket_tcp.cpp b/src/network/socket/qlocalsocket_tcp.cpp
index 9f574d4..5b5e84f 100644
--- a/src/network/socket/qlocalsocket_tcp.cpp
+++ b/src/network/socket/qlocalsocket_tcp.cpp
@@ -102,8 +102,8 @@ void QLocalSocketPrivate::_q_stateChanged(QAbstractSocket::SocketState newState)
switch(newState) {
case QAbstractSocket::UnconnectedState:
state = QLocalSocket::UnconnectedState;
- serverName = QString();
- fullServerName = QString();
+ serverName.clear();
+ fullServerName.clear();
break;
case QAbstractSocket::ConnectingState:
state = QLocalSocket::ConnectingState;
@@ -218,7 +218,7 @@ void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
|| state() == ConnectingState)
return;
- d->errorString = QString();
+ d->errorString.clear();
d->state = ConnectingState;
emit stateChanged(d->state);
@@ -333,8 +333,8 @@ void QLocalSocket::close()
{
Q_D(QLocalSocket);
d->tcpSocket->close();
- d->serverName = QString();
- d->fullServerName = QString();
+ d->serverName.clear();
+ d->fullServerName.clear();
QIODevice::close();
}
diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp
index 73c2465..1ca11d8 100644
--- a/src/network/socket/qlocalsocket_unix.cpp
+++ b/src/network/socket/qlocalsocket_unix.cpp
@@ -109,8 +109,8 @@ void QLocalSocketPrivate::_q_stateChanged(QAbstractSocket::SocketState newState)
switch(newState) {
case QAbstractSocket::UnconnectedState:
state = QLocalSocket::UnconnectedState;
- serverName = QString();
- fullServerName = QString();
+ serverName.clear();
+ fullServerName.clear();
break;
case QAbstractSocket::ConnectingState:
state = QLocalSocket::ConnectingState;
@@ -225,7 +225,7 @@ void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
|| state() == ConnectingState)
return;
- d->errorString = QString();
+ d->errorString.clear();
d->unixSocket.setSocketState(QAbstractSocket::ConnectingState);
d->state = ConnectingState;
emit stateChanged(d->state);
@@ -341,7 +341,7 @@ void QLocalSocketPrivate::_q_connectToSocket()
errorOccurred(QLocalSocket::UnknownSocketError, function);
}
connectingSocket = -1;
- connectingName = QString();
+ connectingName.clear();
connectingOpenMode = 0;
}
@@ -438,10 +438,10 @@ void QLocalSocket::close()
if (d->connectingSocket != -1)
::close(d->connectingSocket);
d->connectingSocket = -1;
- d->connectingName = QString();
+ d->connectingName.clear();
d->connectingOpenMode = 0;
- d->serverName = QString();
- d->fullServerName = QString();
+ d->serverName.clear();
+ d->fullServerName.clear();
QIODevice::close();
}
diff --git a/src/network/socket/qtcpserver.cpp b/src/network/socket/qtcpserver.cpp
index 47a998c..404eee7 100644
--- a/src/network/socket/qtcpserver.cpp
+++ b/src/network/socket/qtcpserver.cpp
@@ -513,6 +513,10 @@ bool QTcpServer::hasPendingConnections() const
0 is returned if this function is called when there are no pending
connections.
+ \note The returned QTcpSocket object cannot be used from another
+ thread. If you want to use an incoming connection from another thread,
+ you need to override incomingConnection().
+
\sa hasPendingConnections()
*/
QTcpSocket *QTcpServer::nextPendingConnection()
@@ -543,6 +547,11 @@ QTcpSocket *QTcpServer::nextPendingConnection()
may not be usable with native socket functions, and should only be
used with QTcpSocket::setSocketDescriptor().
+ \note If you want to handle an incoming connection as a new QTcpSocket
+ object in another thread you have to pass the socketDescriptor
+ to the other thread and create the QTcpSocket object there and
+ use its setSocketDescriptor() method.
+
\sa newConnection(), nextPendingConnection()
*/
void QTcpServer::incomingConnection(int socketDescriptor)
diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp
index 9a9b1b5..fd647e2 100644
--- a/src/network/ssl/qsslcertificate.cpp
+++ b/src/network/ssl/qsslcertificate.cpp
@@ -634,11 +634,11 @@ QByteArray QSslCertificatePrivate::QByteArray_from_X509(X509 *x509, QSsl::Encodi
QByteArray tmp;
for (int i = 0; i <= array.size() - 64; i += 64) {
tmp += QByteArray::fromRawData(array.data() + i, 64);
- tmp += "\n";
+ tmp += '\n';
}
if (int remainder = array.size() % 64) {
tmp += QByteArray::fromRawData(array.data() + array.size() - remainder, remainder);
- tmp += "\n";
+ tmp += '\n';
}
return BEGINCERTSTRING "\n" + tmp + ENDCERTSTRING "\n";
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
index 6947aa7..9623570 100644
--- a/src/network/ssl/qsslsocket.cpp
+++ b/src/network/ssl/qsslsocket.cpp
@@ -1109,7 +1109,7 @@ void QSslSocket::setCiphers(const QString &ciphers)
{
Q_D(QSslSocket);
d->configuration.ciphers.clear();
- foreach (QString cipherName, ciphers.split(QLatin1String(":"),QString::SkipEmptyParts)) {
+ foreach (const QString &cipherName, ciphers.split(QLatin1String(":"),QString::SkipEmptyParts)) {
for (int i = 0; i < 3; ++i) {
// ### Crude
QSslCipher cipher(cipherName, QSsl::SslProtocol(i));
diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp
index 892d330..ce2aee1 100644
--- a/src/network/ssl/qsslsocket_openssl.cpp
+++ b/src/network/ssl/qsslsocket_openssl.cpp
@@ -818,7 +818,7 @@ bool QSslSocketBackendPrivate::startHandshake()
QRegExp regexp(commonName, Qt::CaseInsensitive, QRegExp::Wildcard);
if (!regexp.exactMatch(peerName)) {
bool matched = false;
- foreach (QString altName, configuration.peerCertificate
+ foreach (const QString &altName, configuration.peerCertificate
.alternateSubjectNames().values(QSsl::DnsEntry)) {
regexp.setPattern(altName);
if (regexp.exactMatch(peerName)) {