diff --git a/config.tests/unix/sctp/sctp.cpp b/config.tests/unix/sctp/sctp.cpp index 40d7bb1bcb..61c33d5fc5 100644 --- a/config.tests/unix/sctp/sctp.cpp +++ b/config.tests/unix/sctp/sctp.cpp @@ -37,8 +37,10 @@ ** ****************************************************************************/ -/* Sample program for configure to test for SCTP sockets support -on target platforms. */ +/* + Sample program for configure to test for SCTP sockets support + on target platforms. +*/ #include #include diff --git a/src/network/kernel/qnetworkproxy_win.cpp b/src/network/kernel/qnetworkproxy_win.cpp index c022c718cf..949f9fe12b 100644 --- a/src/network/kernel/qnetworkproxy_win.cpp +++ b/src/network/kernel/qnetworkproxy_win.cpp @@ -288,7 +288,8 @@ static QList parseServerList(const QNetworkProxyQuery &query, con QHash taggedProxies; const QString requiredTag = query.protocolTag(); // windows tags are only for clients - bool checkTags = !requiredTag.isEmpty() && query.queryType() != QNetworkProxyQuery::TcpServer + bool checkTags = !requiredTag.isEmpty() + && query.queryType() != QNetworkProxyQuery::TcpServer && query.queryType() != QNetworkProxyQuery::SctpServer; for (const QString &entry : proxyList) { int server = 0; diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp index 2a9d600630..d7d7dad8e7 100644 --- a/src/network/socket/qnativesocketengine_unix.cpp +++ b/src/network/socket/qnativesocketengine_unix.cpp @@ -915,7 +915,7 @@ qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxS if (recvResult == -1) { switch (errno) { -#if EWOULDBLOCK-0 && EWOULDBLOCK != EAGAIN +#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN case EWOULDBLOCK: #endif case EAGAIN: @@ -1105,7 +1105,7 @@ qint64 QNativeSocketEnginePrivate::nativeSendDatagram(const char *data, qint64 l if (sentBytes < 0) { switch (errno) { -#if EWOULDBLOCK-0 && EWOULDBLOCK != EAGAIN +#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN case EWOULDBLOCK: #endif case EAGAIN: diff --git a/src/network/socket/qsctpsocket.cpp b/src/network/socket/qsctpsocket.cpp index 9ab241f9ab..f65ffa765d 100644 --- a/src/network/socket/qsctpsocket.cpp +++ b/src/network/socket/qsctpsocket.cpp @@ -162,8 +162,12 @@ bool QSctpSocketPrivate::canReadNotification() do { // Determine the size of the pending datagram. qint64 bytesToRead = socketEngine->bytesAvailable(); - if (bytesToRead == 0) + if (bytesToRead == 0) { + // As a corner case, if we can't determine the size of the pending datagram, + // try to read 4K of data from the socket. Subsequent ::recvmsg call either + // fails or returns the actual length of the datagram. bytesToRead = 4096; + } Q_ASSERT((datagramSize + int(bytesToRead)) < MaxByteArraySize); incomingDatagram.resize(datagramSize + int(bytesToRead)); @@ -479,7 +483,7 @@ QNetworkDatagram QSctpSocket::readDatagram() } if (d->currentReadChannel >= d->readHeaders.size() - || (d->readHeaders[d->currentReadChannel].size() == 0)) { + || d->readHeaders[d->currentReadChannel].size() == 0) { Q_ASSERT(d->buffer.isEmpty()); return QNetworkDatagram(); } diff --git a/tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp b/tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp index 70297f8cc4..fc976fbd0d 100644 --- a/tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp +++ b/tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp @@ -118,13 +118,13 @@ void tst_QSctpSocket::constructing() char c; QCOMPARE(socket.getChar(&c), false); - QCOMPARE((int) socket.bytesAvailable(), 0); + QCOMPARE(socket.bytesAvailable(), Q_INT64_C(0)); QCOMPARE(socket.canReadLine(), false); QCOMPARE(socket.readLine(), QByteArray()); - QCOMPARE(socket.socketDescriptor(), (qintptr)-1); - QCOMPARE((int) socket.localPort(), 0); + QCOMPARE(socket.socketDescriptor(), qintptr(-1)); + QCOMPARE(int(socket.localPort()), 0); QVERIFY(socket.localAddress() == QHostAddress()); - QCOMPARE((int) socket.peerPort(), 0); + QCOMPARE(int(socket.peerPort()), 0); QVERIFY(socket.peerAddress() == QHostAddress()); QCOMPARE(socket.error(), QAbstractSocket::UnknownSocketError); QCOMPARE(socket.errorString(), QString("Unknown error")); @@ -139,11 +139,11 @@ void tst_QSctpSocket::bind_data() // iterate all interfaces, add all addresses on them as test data QList interfaces = QNetworkInterface::allInterfaces(); - foreach (const QNetworkInterface &interface, interfaces) { + for (const QNetworkInterface &interface : interfaces) { if (!interface.isValid()) continue; - foreach (const QNetworkAddressEntry &entry, interface.addressEntries()) { + for (const QNetworkAddressEntry &entry : interface.addressEntries()) { if (entry.ip().isInSubnet(QHostAddress::parseSubnet("fe80::/10")) || entry.ip().isInSubnet(QHostAddress::parseSubnet("169.254/16"))) continue; // link-local bind will fail, at least on Linux, so skip it. @@ -178,11 +178,10 @@ void tst_QSctpSocket::bind() QSctpSocket socket; qDebug() << "Binding " << addr; - if (successExpected) { + if (successExpected) QVERIFY2(socket.bind(addr), qPrintable(socket.errorString())); - } else { + else QVERIFY(!socket.bind(addr)); - } QCOMPARE(socket.localAddress(), expectedLocalAddress); } @@ -191,9 +190,9 @@ void tst_QSctpSocket::bind() void tst_QSctpSocket::setInvalidSocketDescriptor() { QSctpSocket socket; - QCOMPARE(socket.socketDescriptor(), (qintptr)INVALID_SOCKET); + QCOMPARE(socket.socketDescriptor(), qintptr(INVALID_SOCKET)); QVERIFY(!socket.setSocketDescriptor(-5, QAbstractSocket::UnconnectedState)); - QCOMPARE(socket.socketDescriptor(), (qintptr)INVALID_SOCKET); + QCOMPARE(socket.socketDescriptor(), qintptr(INVALID_SOCKET)); QCOMPARE(socket.error(), QAbstractSocket::UnsupportedSocketOperationError); } @@ -211,7 +210,7 @@ void tst_QSctpSocket::setSocketDescriptor() QVERIFY(sock != INVALID_SOCKET); QSctpSocket socket; QVERIFY(socket.setSocketDescriptor(sock, QAbstractSocket::UnconnectedState)); - QCOMPARE(socket.socketDescriptor(), (qintptr)sock); + QCOMPARE(socket.socketDescriptor(), qintptr(sock)); QCOMPARE(socket.readChannelCount(), 0); QCOMPARE(socket.writeChannelCount(), 0); @@ -237,7 +236,7 @@ void tst_QSctpSocket::socketDescriptor() QVERIFY(server.listen()); - QCOMPARE(socket.socketDescriptor(), (qintptr)INVALID_SOCKET); + QCOMPARE(socket.socketDescriptor(), qintptr(INVALID_SOCKET)); socket.connectToHost(QHostAddress::LocalHost, server.serverPort()); QVERIFY(server.waitForNewConnection(3000)); if (socket.state() != QAbstractSocket::ConnectedState) {