summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qfilenetworkreply.cpp50
-rw-r--r--src/network/access/qfilenetworkreply_p.h7
-rw-r--r--src/network/socket/qnativesocketengine.cpp8
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp2
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp8
5 files changed, 52 insertions, 23 deletions
diff --git a/src/network/access/qfilenetworkreply.cpp b/src/network/access/qfilenetworkreply.cpp
index 8c5065c..4ac9a8c 100644
--- a/src/network/access/qfilenetworkreply.cpp
+++ b/src/network/access/qfilenetworkreply.cpp
@@ -49,10 +49,15 @@
QT_BEGIN_NAMESPACE
QFileNetworkReplyPrivate::QFileNetworkReplyPrivate()
- : QNetworkReplyPrivate(), realFileSize(0)
+ : QNetworkReplyPrivate(), fileEngine(0), fileSize(0), filePos(0)
{
}
+QFileNetworkReplyPrivate::~QFileNetworkReplyPrivate()
+{
+ delete fileEngine;
+}
+
QFileNetworkReply::~QFileNetworkReply()
{
}
@@ -94,9 +99,8 @@ QFileNetworkReply::QFileNetworkReply(QObject *parent, const QNetworkRequest &req
if (fileName.isEmpty()) {
fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery);
}
- d->realFile.setFileName(fileName);
- QFileInfo fi(d->realFile);
+ QFileInfo fi(fileName);
if (fi.isDir()) {
QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url.toString());
setError(QNetworkReply::ContentOperationNotPermittedError, msg);
@@ -106,14 +110,15 @@ QFileNetworkReply::QFileNetworkReply(QObject *parent, const QNetworkRequest &req
return;
}
- bool opened = d->realFile.open(QIODevice::ReadOnly | QIODevice::Unbuffered);
+ d->fileEngine = QAbstractFileEngine::create(fileName);
+ bool opened = d->fileEngine->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
// could we open the file?
if (!opened) {
QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2")
- .arg(d->realFile.fileName(), d->realFile.errorString());
+ .arg(fileName, d->fileEngine->errorString());
- if (d->realFile.exists()) {
+ if (fi.exists()) {
setError(QNetworkReply::ContentAccessDenied, msg);
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentAccessDenied));
@@ -126,13 +131,13 @@ QFileNetworkReply::QFileNetworkReply(QObject *parent, const QNetworkRequest &req
return;
}
- d->realFileSize = fi.size();
+ d->fileSize = fi.size();
setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified());
- setHeader(QNetworkRequest::ContentLengthHeader, d->realFileSize);
+ setHeader(QNetworkRequest::ContentLengthHeader, d->fileSize);
QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection,
- Q_ARG(qint64, d->realFileSize), Q_ARG(qint64, d->realFileSize));
+ Q_ARG(qint64, d->fileSize), Q_ARG(qint64, d->fileSize));
QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);
}
@@ -146,20 +151,25 @@ void QFileNetworkReply::close()
{
Q_D(QFileNetworkReply);
QNetworkReply::close();
- d->realFile.close();
+ if (d->fileEngine)
+ d->fileEngine->close();
}
void QFileNetworkReply::abort()
{
Q_D(QFileNetworkReply);
QNetworkReply::close();
- d->realFile.close();
+ if (d->fileEngine)
+ d->fileEngine->close();
}
qint64 QFileNetworkReply::bytesAvailable() const
{
Q_D(const QFileNetworkReply);
- return QNetworkReply::bytesAvailable() + d->realFile.bytesAvailable();
+ if (!d->fileEngine)
+ return 0;
+
+ return QNetworkReply::bytesAvailable() + d->fileSize - d->filePos;
}
bool QFileNetworkReply::isSequential () const
@@ -170,7 +180,7 @@ bool QFileNetworkReply::isSequential () const
qint64 QFileNetworkReply::size() const
{
Q_D(const QFileNetworkReply);
- return d->realFileSize;
+ return d->fileSize;
}
/*!
@@ -179,11 +189,17 @@ qint64 QFileNetworkReply::size() const
qint64 QFileNetworkReply::readData(char *data, qint64 maxlen)
{
Q_D(QFileNetworkReply);
- qint64 ret = d->realFile.read(data, maxlen);
- if (ret == 0 && bytesAvailable() == 0)
+ if (!d->fileEngine)
+ return -1;
+
+ qint64 ret = d->fileEngine->read(data, maxlen);
+ if (ret == 0 && bytesAvailable() == 0) {
return -1; // everything had been read
- else
- return ret;
+ } else if (ret > 0) {
+ d->filePos += ret;
+ }
+
+ return ret;
}
diff --git a/src/network/access/qfilenetworkreply_p.h b/src/network/access/qfilenetworkreply_p.h
index 125fa2e..710ec9f 100644
--- a/src/network/access/qfilenetworkreply_p.h
+++ b/src/network/access/qfilenetworkreply_p.h
@@ -57,6 +57,7 @@
#include "qnetworkreply_p.h"
#include "qnetworkaccessmanager.h"
#include <QFile>
+#include <QAbstractFileEngine>
QT_BEGIN_NAMESPACE
@@ -85,9 +86,11 @@ class QFileNetworkReplyPrivate: public QNetworkReplyPrivate
{
public:
QFileNetworkReplyPrivate();
+ ~QFileNetworkReplyPrivate();
- QFile realFile;
- qint64 realFileSize;
+ QAbstractFileEngine *fileEngine;
+ qint64 fileSize;
+ qint64 filePos;
virtual bool isFinished() const;
diff --git a/src/network/socket/qnativesocketengine.cpp b/src/network/socket/qnativesocketengine.cpp
index 6e1df93..a890b3b 100644
--- a/src/network/socket/qnativesocketengine.cpp
+++ b/src/network/socket/qnativesocketengine.cpp
@@ -778,6 +778,14 @@ qint64 QNativeSocketEngine::read(char *data, qint64 maxSize)
QNativeSocketEnginePrivate::RemoteHostClosedErrorString);
close();
return -1;
+ } else if (readBytes == -1) {
+ if (!d->hasSetSocketError) {
+ d->hasSetSocketError = true;
+ d->socketError = QAbstractSocket::NetworkError;
+ d->socketErrorString = qt_error_string();
+ }
+ close();
+ return -1;
}
return readBytes;
}
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index d3b0fe5..9a2c349 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -903,7 +903,7 @@ qint64 QNativeSocketEnginePrivate::nativeRead(char *data, qint64 maxSize)
case EBADF:
case EINVAL:
case EIO:
- setError(QAbstractSocket::NetworkError, ReadErrorString);
+ //error string is now set in read(), not here in nativeRead()
break;
#ifdef Q_OS_SYMBIAN
case EPIPE:
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index 7088a57..8177b4f 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -1068,7 +1068,7 @@ qint64 QNativeSocketEnginePrivate::nativeRead(char *data, qint64 maxLength)
break;
case WSAEBADF:
case WSAEINVAL:
- setError(QAbstractSocket::NetworkError, ReadErrorString);
+ //error string is now set in read(), not here in nativeRead()
break;
case WSAECONNRESET:
case WSAECONNABORTED:
@@ -1199,8 +1199,10 @@ void QNativeSocketEnginePrivate::nativeClose()
#if defined (QTCPSOCKETENGINE_DEBUG)
qDebug("QNativeSocketEnginePrivate::nativeClose()");
#endif
- linger l = {1, 0};
- ::setsockopt(socketDescriptor, SOL_SOCKET, SO_DONTLINGER, (char*)&l, sizeof(l));
+ // We were doing a setsockopt here before with SO_DONTLINGER. (However with kind of wrong
+ // usage of parameters, it wants a BOOL but we used a struct and pretended it to be bool).
+ // We don't think setting this option should be done here, if a user wants it she/he can
+ // do it manually with socketDescriptor()/setSocketDescriptor();
::closesocket(socketDescriptor);
}