Fix some syntax issues in SCTP implementation

Change-Id: I718fd060e313d544a5470fa20183db04ef89b1ca
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Alex Trotsenko 2016-08-02 14:51:56 +03:00
parent c0637c0298
commit 733c4de36e
5 changed files with 26 additions and 20 deletions

View File

@ -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 <sys/types.h>
#include <sys/socket.h>

View File

@ -288,7 +288,8 @@ static QList<QNetworkProxy> parseServerList(const QNetworkProxyQuery &query, con
QHash<QString, QNetworkProxy> 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;

View File

@ -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:

View File

@ -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();
}

View File

@ -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<QNetworkInterface> 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) {