summaryrefslogtreecommitdiffstats
path: root/src/network/socket
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-07-11 17:17:13 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-07-11 17:17:51 +0200
commit4dac45c9ee59ff6586d90d423654da91523ab679 (patch)
treecd4a4adf2cbc9e77bf86d2d11e71ec66afdf3be4 /src/network/socket
parent078cd61751aeaa310d35a3d596a21a36004a1a0f (diff)
parentf44850b5c3464cdda0ee9b1ee858d95f3ffaa3e2 (diff)
Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
Diffstat (limited to 'src/network/socket')
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp24
-rw-r--r--src/network/socket/qsocks5socketengine.cpp25
2 files changed, 28 insertions, 21 deletions
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index 24e8eabb6e..b429b3c365 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -608,13 +608,13 @@ bool QNativeSocketEnginePrivate::fetchConnectionParameters()
socketType = qt_socket_getType(socketDescriptor);
#if defined (QNATIVESOCKETENGINE_DEBUG)
- QString socketProtocolStr = "UnknownProtocol";
- if (socketProtocol == QAbstractSocket::IPv4Protocol) socketProtocolStr = "IPv4Protocol";
- else if (socketProtocol == QAbstractSocket::IPv6Protocol) socketProtocolStr = "IPv6Protocol";
+ QString socketProtocolStr = QStringLiteral("UnknownProtocol");
+ if (socketProtocol == QAbstractSocket::IPv4Protocol) socketProtocolStr = QStringLiteral("IPv4Protocol");
+ else if (socketProtocol == QAbstractSocket::IPv6Protocol) socketProtocolStr = QStringLiteral("IPv6Protocol");
- QString socketTypeStr = "UnknownSocketType";
- if (socketType == QAbstractSocket::TcpSocket) socketTypeStr = "TcpSocket";
- else if (socketType == QAbstractSocket::UdpSocket) socketTypeStr = "UdpSocket";
+ QString socketTypeStr = QStringLiteral("UnknownSocketType");
+ if (socketType == QAbstractSocket::TcpSocket) socketTypeStr = QStringLiteral("TcpSocket");
+ else if (socketType == QAbstractSocket::UdpSocket) socketTypeStr = QStringLiteral("UdpSocket");
qDebug("QNativeSocketEnginePrivate::fetchConnectionParameters() localAddress == %s, localPort = %i, peerAddress == %s, peerPort = %i, socketProtocol == %s, socketType == %s", localAddress.toString().toLatin1().constData(), localPort, peerAddress.toString().toLatin1().constData(), peerPort, socketProtocolStr.toLatin1().constData(), socketTypeStr.toLatin1().constData());
#endif
@@ -1477,8 +1477,8 @@ qint64 QNativeSocketEnginePrivate::nativeWrite(const char *data, qint64 len)
}
#if defined (QNATIVESOCKETENGINE_DEBUG)
- qDebug("QNativeSocketEnginePrivate::nativeWrite(%p \"%s\", %li) == %li",
- data, qt_prettyDebug(data, qMin((int)ret, 16), (int)ret).data(), (int)len, (int)ret);
+ qDebug("QNativeSocketEnginePrivate::nativeWrite(%p \"%s\", %lli) == %lli",
+ data, qt_prettyDebug(data, qMin(int(ret), 16), int(ret)).data(), len, ret);
#endif
return ret;
@@ -1520,11 +1520,11 @@ qint64 QNativeSocketEnginePrivate::nativeRead(char *data, qint64 maxLength)
#if defined (QNATIVESOCKETENGINE_DEBUG)
if (ret != -2) {
- qDebug("QNativeSocketEnginePrivate::nativeRead(%p \"%s\", %li) == %li",
- data, qt_prettyDebug(data, qMin((int)bytesRead, 16), (int)bytesRead).data(), (int)maxLength, (int)ret);
+ qDebug("QNativeSocketEnginePrivate::nativeRead(%p \"%s\", %lli) == %lli",
+ data, qt_prettyDebug(data, qMin(int(bytesRead), 16), int(bytesRead)).data(), maxLength, ret);
} else {
- qDebug("QNativeSocketEnginePrivate::nativeRead(%p, %li) == -2 (WOULD BLOCK)",
- data, int(maxLength));
+ qDebug("QNativeSocketEnginePrivate::nativeRead(%p, %lli) == -2 (WOULD BLOCK)",
+ data, maxLength);
}
#endif
diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp
index 27657956df..4207832c4c 100644
--- a/src/network/socket/qsocks5socketengine.cpp
+++ b/src/network/socket/qsocks5socketengine.cpp
@@ -322,8 +322,8 @@ public:
protected:
void timerEvent(QTimerEvent * event) override;
- QMutex mutex;
- int sweepTimerId;
+ QRecursiveMutex mutex;
+ int sweepTimerId = -1;
//socket descriptor, data, timestamp
QHash<int, QSocks5BindData *> store;
};
@@ -331,8 +331,6 @@ protected:
Q_GLOBAL_STATIC(QSocks5BindStore, socks5BindStore)
QSocks5BindStore::QSocks5BindStore()
- : mutex(QMutex::Recursive)
- , sweepTimerId(-1)
{
QCoreApplication *app = QCoreApplication::instance();
if (app && app->thread() != thread())
@@ -801,9 +799,9 @@ void QSocks5SocketEnginePrivate::sendRequestMethod()
QByteArray buf;
buf.reserve(270); // big enough for domain name;
- buf[0] = S5_VERSION_5;
- buf[1] = command;
- buf[2] = 0x00;
+ buf.append(char(S5_VERSION_5));
+ buf.append(command);
+ buf.append('\0');
if (peerName.isEmpty() && !qt_socks5_set_host_address_and_port(address, port, &buf)) {
QSOCKS5_DEBUG << "error setting address" << address << " : " << port;
//### set error code ....
@@ -1188,6 +1186,8 @@ void QSocks5SocketEnginePrivate::_q_controlSocketReadNotification()
break;
case RequestMethodSent:
parseRequestMethodReply();
+ if (socks5State == Connected && data->controlSocket->bytesAvailable())
+ _q_controlSocketReadNotification();
break;
case Connected: {
QByteArray buf;
@@ -1611,8 +1611,10 @@ qint64 QSocks5SocketEngine::readDatagram(char *data, qint64 maxlen, QIpPacketHea
QSocks5RevivedDatagram datagram = d->udpData->pendingDatagrams.dequeue();
int copyLen = qMin<int>(maxlen, datagram.data.size());
memcpy(data, datagram.data.constData(), copyLen);
- header->senderAddress = datagram.address;
- header->senderPort = datagram.port;
+ if (header) {
+ header->senderAddress = datagram.address;
+ header->senderPort = datagram.port;
+ }
return copyLen;
#else
Q_UNUSED(data)
@@ -1749,6 +1751,11 @@ bool QSocks5SocketEngine::waitForRead(int msecs, bool *timedOut)
return false;
if (d->data->controlSocket->state() == QAbstractSocket::UnconnectedState)
return true;
+ if (bytesAvailable() && d->readNotificationPending) {
+ // We've got some data incoming, but the queued call hasn't been performed yet.
+ // The data is where we expect it to be already, so just return true.
+ return true;
+ }
// we're connected
if (d->mode == QSocks5SocketEnginePrivate::ConnectMode ||