summaryrefslogtreecommitdiffstats
path: root/src/network/socket
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-05-06 09:07:18 +0200
committerLiang Qi <liang.qi@qt.io>2016-05-06 15:36:44 +0200
commitdbef41f43ece97d8ac4d6b63f7a36afcb7e7b7f7 (patch)
tree334ebaec198a7f31d1e3a4639c70fbb8bb116af2 /src/network/socket
parent52d30e2850769d589772576e4714a14241c7da6e (diff)
parentf57d8f1341587e6b2aa84b8404aa218432584206 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: examples/qtestlib/tutorial5/containers.cpp examples/widgets/tools/tools.pro src/corelib/io/qprocess.cpp src/corelib/io/qprocess_unix.cpp src/corelib/io/qprocess_win.cpp src/network/kernel/qdnslookup_unix.cpp src/plugins/platforms/xcb/qxcbconnection_xi2.cpp src/testlib/qtestcase.cpp tools/configure/configureapp.cpp Change-Id: I838ae7f082535a67a4a53aa13a21ba5580758be8
Diffstat (limited to 'src/network/socket')
-rw-r--r--src/network/socket/qlocalsocket.h2
-rw-r--r--src/network/socket/qlocalsocket_p.h3
-rw-r--r--src/network/socket/qlocalsocket_win.cpp24
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp29
4 files changed, 33 insertions, 25 deletions
diff --git a/src/network/socket/qlocalsocket.h b/src/network/socket/qlocalsocket.h
index da91ef0e85..0eecab206b 100644
--- a/src/network/socket/qlocalsocket.h
+++ b/src/network/socket/qlocalsocket.h
@@ -130,7 +130,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAbstractSocket::SocketState))
Q_PRIVATE_SLOT(d_func(), void _q_error(QAbstractSocket::SocketError))
#elif defined(Q_OS_WIN)
- Q_PRIVATE_SLOT(d_func(), void _q_bytesWritten(qint64))
+ Q_PRIVATE_SLOT(d_func(), void _q_canWrite())
Q_PRIVATE_SLOT(d_func(), void _q_pipeClosed())
Q_PRIVATE_SLOT(d_func(), void _q_winError(ulong, const QString &))
#else
diff --git a/src/network/socket/qlocalsocket_p.h b/src/network/socket/qlocalsocket_p.h
index 0f84aeea3e..cf36887e92 100644
--- a/src/network/socket/qlocalsocket_p.h
+++ b/src/network/socket/qlocalsocket_p.h
@@ -130,8 +130,7 @@ public:
~QLocalSocketPrivate();
void destroyPipeHandles();
void setErrorString(const QString &function);
- void startNextWrite();
- void _q_bytesWritten(qint64 bytes);
+ void _q_canWrite();
void _q_pipeClosed();
void _q_winError(ulong windowsError, const QString &function);
HANDLE handle;
diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp
index 5fc34c3ed6..66b461522b 100644
--- a/src/network/socket/qlocalsocket_win.cpp
+++ b/src/network/socket/qlocalsocket_win.cpp
@@ -218,11 +218,12 @@ qint64 QLocalSocket::writeData(const char *data, qint64 len)
memcpy(dest, data, len);
if (!d->pipeWriter) {
d->pipeWriter = new QWindowsPipeWriter(d->handle, this);
- QObjectPrivate::connect(d->pipeWriter, &QWindowsPipeWriter::bytesWritten,
- d, &QLocalSocketPrivate::_q_bytesWritten);
+ connect(d->pipeWriter, &QWindowsPipeWriter::bytesWritten,
+ this, &QLocalSocket::bytesWritten);
+ QObjectPrivate::connect(d->pipeWriter, &QWindowsPipeWriter::canWrite,
+ d, &QLocalSocketPrivate::_q_canWrite);
}
- if (!d->pipeWriter->isWriteOperationActive())
- d->startNextWrite();
+ d->_q_canWrite();
return len;
}
@@ -275,7 +276,7 @@ qint64 QLocalSocket::bytesAvailable() const
qint64 QLocalSocket::bytesToWrite() const
{
Q_D(const QLocalSocket);
- return d->writeBuffer.size();
+ return d->writeBuffer.size() + (d->pipeWriter ? d->pipeWriter->bytesToWrite() : 0);
}
bool QLocalSocket::canReadLine() const
@@ -358,7 +359,7 @@ bool QLocalSocket::setSocketDescriptor(qintptr socketDescriptor,
return true;
}
-void QLocalSocketPrivate::startNextWrite()
+void QLocalSocketPrivate::_q_canWrite()
{
Q_Q(QLocalSocket);
if (writeBuffer.isEmpty()) {
@@ -366,18 +367,11 @@ void QLocalSocketPrivate::startNextWrite()
q->close();
} else {
Q_ASSERT(pipeWriter);
- pipeWriter->write(writeBuffer.readPointer(), writeBuffer.nextDataBlockSize());
+ if (!pipeWriter->isWriteOperationActive())
+ pipeWriter->write(writeBuffer.read());
}
}
-void QLocalSocketPrivate::_q_bytesWritten(qint64 bytes)
-{
- Q_Q(QLocalSocket);
- writeBuffer.free(bytes);
- startNextWrite();
- emit q->bytesWritten(bytes);
-}
-
qintptr QLocalSocket::socketDescriptor() const
{
Q_D(const QLocalSocket);
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index 6ff5c884f7..5ffe7b11b8 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -574,6 +574,19 @@ bool QNativeSocketEnginePrivate::fetchConnectionParameters()
}
}
+ // Some Windows kernels return a v4-mapped QHostAddress::AnyIPv4 as a
+ // local address of the socket which bound on both IPv4 and IPv6 interfaces.
+ // This address does not match to any special address and should not be used
+ // to send the data. So, replace it with QHostAddress::Any.
+ if (socketProtocol == QAbstractSocket::IPv6Protocol) {
+ bool ok = false;
+ const quint32 localIPv4 = localAddress.toIPv4Address(&ok);
+ if (ok && localIPv4 == INADDR_ANY) {
+ socketProtocol = QAbstractSocket::AnyIPProtocol;
+ localAddress = QHostAddress::Any;
+ }
+ }
+
memset(&sa, 0, sizeof(sa));
if (::getpeername(socketDescriptor, &sa.a, &sockAddrSize) == 0) {
qt_socket_getPortAndAddress(socketDescriptor, &sa, &peerPort, &peerAddress);
@@ -1186,7 +1199,7 @@ qint64 QNativeSocketEnginePrivate::nativePendingDatagramSize() const
#endif
#if defined (QNATIVESOCKETENGINE_DEBUG)
- qDebug("QNativeSocketEnginePrivate::nativePendingDatagramSize() == %li", ret);
+ qDebug("QNativeSocketEnginePrivate::nativePendingDatagramSize() == %lli", ret);
#endif
return ret;
@@ -1292,10 +1305,11 @@ qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxL
}
#if defined (QNATIVESOCKETENGINE_DEBUG)
- qDebug("QNativeSocketEnginePrivate::nativeReceiveDatagram(%p \"%s\", %li, %s, %i) == %li",
+ bool printSender = (ret != -1 && (options & QNativeSocketEngine::WantDatagramSender) != 0);
+ qDebug("QNativeSocketEnginePrivate::nativeReceiveDatagram(%p \"%s\", %lli, %s, %i) == %lli",
data, qt_prettyDebug(data, qMin<qint64>(ret, 16), ret).data(), maxLength,
- address ? address->toString().toLatin1().constData() : "(nil)",
- port ? *port : 0, ret);
+ printSender ? header->senderAddress.toString().toLatin1().constData() : "(unknown)",
+ printSender ? header->senderPort : 0, ret);
#endif
return ret;
@@ -1407,9 +1421,10 @@ qint64 QNativeSocketEnginePrivate::nativeSendDatagram(const char *data, qint64 l
}
#if defined (QNATIVESOCKETENGINE_DEBUG)
- qDebug("QNativeSocketEnginePrivate::nativeSendDatagram(%p \"%s\", %li, \"%s\", %i) == %li", data,
- qt_prettyDebug(data, qMin<qint64>(len, 16), len).data(), 0, address.toString().toLatin1().constData(),
- port, ret);
+ qDebug("QNativeSocketEnginePrivate::nativeSendDatagram(%p \"%s\", %lli, \"%s\", %i) == %lli", data,
+ qt_prettyDebug(data, qMin<qint64>(len, 16), len).data(), len,
+ header.destinationAddress.toString().toLatin1().constData(),
+ header.destinationPort, ret);
#endif
return ret;