summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-10-23 14:01:35 +0200
committerOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2015-10-23 14:45:03 +0200
commit790aef362fd195adf97d8c780a7cbbbade27d51f (patch)
tree8be464687ab21806cfe9f7ada27098b563aa41b2 /src/network
parent9720efbd1035c2e939b0581163e6d804c713dd96 (diff)
parent07475c662eb73c833da2d461b8ef2702ca1e2cfb (diff)
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts: .qmake.conf configure src/corelib/global/qglobal.h src/tools/qdoc/node.cpp src/tools/qdoc/qdocdatabase.cpp tests/auto/corelib/io/qsettings/tst_qsettings.cpp tools/configure/configureapp.cpp Change-Id: I66028ae5e441a06b73ee85ba72a03a3af3e8593f
Diffstat (limited to 'src/network')
-rw-r--r--src/network/doc/qtnetwork.qdocconf2
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp6
-rw-r--r--src/network/socket/qnativesocketengine_winrt.cpp35
3 files changed, 39 insertions, 4 deletions
diff --git a/src/network/doc/qtnetwork.qdocconf b/src/network/doc/qtnetwork.qdocconf
index 2a8e577dda..87e322d6c0 100644
--- a/src/network/doc/qtnetwork.qdocconf
+++ b/src/network/doc/qtnetwork.qdocconf
@@ -4,7 +4,7 @@ project = QtNetwork
description = Qt Network Reference Documentation
version = $QT_VERSION
-examplesinstallpath = network
+examplesinstallpath = qtbase/network
qhp.projects = QtNetwork
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index fab4d1c532..cba1ac52be 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -806,7 +806,11 @@ qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxS
QAbstractSocketEngine::PacketHeaderOptions options)
{
// we use quintptr to force the alignment
- quintptr cbuf[(CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(sizeof(int)) + sizeof(quintptr) - 1) / sizeof(quintptr)];
+ quintptr cbuf[(CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(sizeof(int))
+#if !defined(IP_PKTINFO) && defined(IP_RECVIF) && defined(Q_OS_BSD4)
+ + CMSG_SPACE(sizeof(sockaddr_dl))
+#endif
+ + sizeof(quintptr) - 1) / sizeof(quintptr)];
struct msghdr msg;
struct iovec vec;
diff --git a/src/network/socket/qnativesocketengine_winrt.cpp b/src/network/socket/qnativesocketengine_winrt.cpp
index 44de7f8526..d41bd4d313 100644
--- a/src/network/socket/qnativesocketengine_winrt.cpp
+++ b/src/network/socket/qnativesocketengine_winrt.cpp
@@ -420,6 +420,16 @@ void QNativeSocketEngine::close()
{
Q_D(QNativeSocketEngine);
+ if (d->closingDown)
+ return;
+
+ d->closingDown = true;
+
+
+ d->notifyOnRead = false;
+ d->notifyOnWrite = false;
+ d->notifyOnException = false;
+
if (d->connectOp) {
ComPtr<IAsyncInfo> info;
d->connectOp.As(&info);
@@ -440,7 +450,6 @@ void QNativeSocketEngine::close()
}
if (socket) {
- d->closingDown = true;
socket->Close();
d->socketDescriptor = -1;
}
@@ -498,6 +507,14 @@ qint64 QNativeSocketEngine::read(char *data, qint64 maxlen)
if (d->socketType != QAbstractSocket::TcpSocket)
return -1;
+ // There will be a read notification when the socket was closed by the remote host. If that
+ // happens and there isn't anything left in the buffer, we have to return -1 in order to signal
+ // the closing of the socket.
+ if (d->readBytes.pos() == d->readBytes.size() && d->socketState != QAbstractSocket::ConnectedState) {
+ close();
+ return -1;
+ }
+
QMutexLocker mutexLocker(&d->readMutex);
return d->readBytes.read(data, maxlen);
}
@@ -1184,8 +1201,16 @@ HRESULT QNativeSocketEnginePrivate::handleReadyRead(IAsyncBufferOperation *async
if (wasDeleted || isDeletingChildren)
return S_OK;
- if (status == Error || status == Canceled)
+ // A read in UnconnectedState will close the socket and return -1 and thus tell the caller,
+ // that the connection was closed. The socket cannot be closed here, as the subsequent read
+ // might fail then.
+ if (status == Error || status == Canceled) {
+ setError(QAbstractSocket::NetworkError, RemoteHostClosedErrorString);
+ socketState = QAbstractSocket::UnconnectedState;
+ if (notifyOnRead)
+ emit q->readReady();
return S_OK;
+ }
ComPtr<IBuffer> buffer;
HRESULT hr = asyncInfo->GetResults(&buffer);
@@ -1194,7 +1219,13 @@ HRESULT QNativeSocketEnginePrivate::handleReadyRead(IAsyncBufferOperation *async
UINT32 bufferLength;
hr = buffer->get_Length(&bufferLength);
Q_ASSERT_SUCCEEDED(hr);
+ // A zero sized buffer length signals, that the remote host closed the connection. The socket
+ // cannot be closed though, as the following read might have socket descriptor -1 and thus and
+ // the closing of the socket won't be communicated to the caller. So only the error is set. The
+ // actual socket close happens inside of read.
if (!bufferLength) {
+ setError(QAbstractSocket::NetworkError, RemoteHostClosedErrorString);
+ socketState = QAbstractSocket::UnconnectedState;
if (notifyOnRead)
emit q->readReady();
return S_OK;