Fix SCTP API according to Qt conventions

inDatagramMode() -> isInDatagramMode()
maxChannelCount -> maximumChannelCount

Change-Id: Ib64bf52cc3b40354927ee11e3f41d47e84c6d9c4
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Friedemann Kleint 2016-11-21 10:57:25 +01:00
parent d207738245
commit 7920cfe46a
8 changed files with 52 additions and 52 deletions

View File

@ -66,7 +66,7 @@ Server::Server(QWidget *parent)
setWindowTitle(tr("Multi-stream Server")); setWindowTitle(tr("Multi-stream Server"));
sctpServer = new QSctpServer(this); sctpServer = new QSctpServer(this);
sctpServer->setMaxChannelCount(NumberOfChannels); sctpServer->setMaximumChannelCount(NumberOfChannels);
statusLabel = new QLabel; statusLabel = new QLabel;
QPushButton *quitButton = new QPushButton(tr("Quit")); QPushButton *quitButton = new QPushButton(tr("Quit"));

View File

@ -60,7 +60,7 @@
The most common way to use QSctpServer is to construct an object The most common way to use QSctpServer is to construct an object
and set the maximum number of channels that the server is and set the maximum number of channels that the server is
prepared to support, by calling setMaxChannelCount(). You can set prepared to support, by calling setMaximumChannelCount(). You can set
the TCP emulation mode by passing a negative argument in this the TCP emulation mode by passing a negative argument in this
call. Also, a special value of 0 (the default) indicates to use call. Also, a special value of 0 (the default) indicates to use
the peer's value as the actual number of channels. The new incoming the peer's value as the actual number of channels. The new incoming
@ -102,7 +102,7 @@ QT_BEGIN_NAMESPACE
/*! \internal /*! \internal
*/ */
QSctpServerPrivate::QSctpServerPrivate() QSctpServerPrivate::QSctpServerPrivate()
: maxChannelCount(0) : maximumChannelCount(0)
{ {
} }
@ -119,7 +119,7 @@ void QSctpServerPrivate::configureCreatedSocket()
QTcpServerPrivate::configureCreatedSocket(); QTcpServerPrivate::configureCreatedSocket();
if (socketEngine) if (socketEngine)
socketEngine->setOption(QAbstractSocketEngine::MaxStreamsSocketOption, socketEngine->setOption(QAbstractSocketEngine::MaxStreamsSocketOption,
maxChannelCount == -1 ? 1 : maxChannelCount); maximumChannelCount == -1 ? 1 : maximumChannelCount);
} }
/*! /*!
@ -128,7 +128,7 @@ void QSctpServerPrivate::configureCreatedSocket()
Sets the datagram operation mode. The \a parent argument is passed Sets the datagram operation mode. The \a parent argument is passed
to QObject's constructor. to QObject's constructor.
\sa setMaxChannelCount(), listen(), setSocketDescriptor() \sa setMaximumChannelCount(), listen(), setSocketDescriptor()
*/ */
QSctpServer::QSctpServer(QObject *parent) QSctpServer::QSctpServer(QObject *parent)
: QTcpServer(QAbstractSocket::SctpSocket, *new QSctpServerPrivate, parent) : QTcpServer(QAbstractSocket::SctpSocket, *new QSctpServerPrivate, parent)
@ -159,19 +159,19 @@ QSctpServer::~QSctpServer()
Call this method only when QSctpServer is in UnconnectedState. Call this method only when QSctpServer is in UnconnectedState.
\sa maxChannelCount(), QSctpSocket \sa maximumChannelCount(), QSctpSocket
*/ */
void QSctpServer::setMaxChannelCount(int count) void QSctpServer::setMaximumChannelCount(int count)
{ {
Q_D(QSctpServer); Q_D(QSctpServer);
if (d->state != QAbstractSocket::UnconnectedState) { if (d->state != QAbstractSocket::UnconnectedState) {
qWarning("QSctpServer::setMaxChannelCount() is only allowed in UnconnectedState"); qWarning("QSctpServer::setMaximumChannelCount() is only allowed in UnconnectedState");
return; return;
} }
#if defined(QSCTPSERVER_DEBUG) #if defined(QSCTPSERVER_DEBUG)
qDebug("QSctpServer::setMaxChannelCount(%i)", count); qDebug("QSctpServer::setMaximumChannelCount(%i)", count);
#endif #endif
d->maxChannelCount = count; d->maximumChannelCount = count;
} }
/*! /*!
@ -183,11 +183,11 @@ void QSctpServer::setMaxChannelCount(int count)
Returns -1, if QSctpServer running in TCP emulation mode. Returns -1, if QSctpServer running in TCP emulation mode.
\sa setMaxChannelCount() \sa setMaximumChannelCount()
*/ */
int QSctpServer::maxChannelCount() const int QSctpServer::maximumChannelCount() const
{ {
return d_func()->maxChannelCount; return d_func()->maximumChannelCount;
} }
/*! \reimp /*! \reimp
@ -199,7 +199,7 @@ void QSctpServer::incomingConnection(qintptr socketDescriptor)
#endif #endif
QSctpSocket *socket = new QSctpSocket(this); QSctpSocket *socket = new QSctpSocket(this);
socket->setMaxChannelCount(d_func()->maxChannelCount); socket->setMaximumChannelCount(d_func()->maximumChannelCount);
socket->setSocketDescriptor(socketDescriptor); socket->setSocketDescriptor(socketDescriptor);
addPendingConnection(socket); addPendingConnection(socket);
} }
@ -234,7 +234,7 @@ QSctpSocket *QSctpServer::nextPendingDatagramConnection()
QSctpSocket *socket = qobject_cast<QSctpSocket *>(i.next()); QSctpSocket *socket = qobject_cast<QSctpSocket *>(i.next());
Q_ASSERT(socket); Q_ASSERT(socket);
if (socket->inDatagramMode()) { if (socket->isInDatagramMode()) {
i.remove(); i.remove();
Q_ASSERT(d->socketEngine); Q_ASSERT(d->socketEngine);
d->socketEngine->setReadNotificationEnabled(true); d->socketEngine->setReadNotificationEnabled(true);

View File

@ -57,8 +57,8 @@ public:
explicit QSctpServer(QObject *parent = nullptr); explicit QSctpServer(QObject *parent = nullptr);
virtual ~QSctpServer(); virtual ~QSctpServer();
void setMaxChannelCount(int count); void setMaximumChannelCount(int count);
int maxChannelCount() const; int maximumChannelCount() const;
QSctpSocket *nextPendingDatagramConnection(); QSctpSocket *nextPendingDatagramConnection();

View File

@ -64,7 +64,7 @@ public:
QSctpServerPrivate(); QSctpServerPrivate();
virtual ~QSctpServerPrivate(); virtual ~QSctpServerPrivate();
int maxChannelCount; int maximumChannelCount;
void configureCreatedSocket() Q_DECL_OVERRIDE; void configureCreatedSocket() Q_DECL_OVERRIDE;
}; };

View File

@ -83,14 +83,14 @@
\endlist \endlist
To set a continuous byte stream mode, instantiate QSctpSocket and To set a continuous byte stream mode, instantiate QSctpSocket and
call setMaxChannelCount() with a negative value. This gives the call setMaximumChannelCount() with a negative value. This gives the
ability to use QSctpSocket as a regular buffered QTcpSocket. You ability to use QSctpSocket as a regular buffered QTcpSocket. You
can call connectToHost() to initiate connection with endpoint, can call connectToHost() to initiate connection with endpoint,
write() to transmit and read() to receive data from the peer, but write() to transmit and read() to receive data from the peer, but
you cannot distinguish message boundaries. you cannot distinguish message boundaries.
By default, QSctpSocket operates in datagram mode. Before By default, QSctpSocket operates in datagram mode. Before
connecting, call setMaxChannelCount() to set the maximum number of connecting, call setMaximumChannelCount() to set the maximum number of
channels that the application is prepared to support. This number channels that the application is prepared to support. This number
is a parameter negotiated with the remote endpoint and its value is a parameter negotiated with the remote endpoint and its value
can be bounded by the operating system. The default value of 0 can be bounded by the operating system. The default value of 0
@ -130,7 +130,7 @@ QT_BEGIN_NAMESPACE
/*! \internal /*! \internal
*/ */
QSctpSocketPrivate::QSctpSocketPrivate() QSctpSocketPrivate::QSctpSocketPrivate()
: maxChannelCount(0) : maximumChannelCount(0)
{ {
} }
@ -150,7 +150,7 @@ bool QSctpSocketPrivate::canReadNotification()
#endif #endif
// Handle TCP emulation mode in the base implementation. // Handle TCP emulation mode in the base implementation.
if (!q->inDatagramMode()) if (!q->isInDatagramMode())
return QTcpSocketPrivate::canReadNotification(); return QTcpSocketPrivate::canReadNotification();
const int savedCurrentChannel = currentReadChannel; const int savedCurrentChannel = currentReadChannel;
@ -248,7 +248,7 @@ bool QSctpSocketPrivate::writeToSocket()
#endif #endif
// Handle TCP emulation mode in the base implementation. // Handle TCP emulation mode in the base implementation.
if (!q->inDatagramMode()) if (!q->isInDatagramMode())
return QTcpSocketPrivate::writeToSocket(); return QTcpSocketPrivate::writeToSocket();
if (!socketEngine) if (!socketEngine)
@ -331,7 +331,7 @@ void QSctpSocketPrivate::configureCreatedSocket()
{ {
if (socketEngine) if (socketEngine)
socketEngine->setOption(QAbstractSocketEngine::MaxStreamsSocketOption, socketEngine->setOption(QAbstractSocketEngine::MaxStreamsSocketOption,
maxChannelCount < 0 ? 1 : maxChannelCount); maximumChannelCount < 0 ? 1 : maximumChannelCount);
} }
/*! /*!
@ -340,7 +340,7 @@ void QSctpSocketPrivate::configureCreatedSocket()
Sets the datagram operation mode. The \a parent argument is passed Sets the datagram operation mode. The \a parent argument is passed
to QObject's constructor. to QObject's constructor.
\sa socketType(), setMaxChannelCount() \sa socketType(), setMaximumChannelCount()
*/ */
QSctpSocket::QSctpSocket(QObject *parent) QSctpSocket::QSctpSocket(QObject *parent)
: QTcpSocket(SctpSocket, *new QSctpSocketPrivate, parent) : QTcpSocket(SctpSocket, *new QSctpSocketPrivate, parent)
@ -418,19 +418,19 @@ void QSctpSocket::disconnectFromHost()
Call this method only when QSctpSocket is in UnconnectedState. Call this method only when QSctpSocket is in UnconnectedState.
\sa maxChannelCount(), readChannelCount(), writeChannelCount() \sa maximumChannelCount(), readChannelCount(), writeChannelCount()
*/ */
void QSctpSocket::setMaxChannelCount(int count) void QSctpSocket::setMaximumChannelCount(int count)
{ {
Q_D(QSctpSocket); Q_D(QSctpSocket);
if (d->state != QAbstractSocket::UnconnectedState) { if (d->state != QAbstractSocket::UnconnectedState) {
qWarning("QSctpSocket::setMaxChannelCount() is only allowed in UnconnectedState"); qWarning("QSctpSocket::setMaximumChannelCount() is only allowed in UnconnectedState");
return; return;
} }
#if defined(QSCTPSOCKET_DEBUG) #if defined(QSCTPSOCKET_DEBUG)
qDebug("QSctpSocket::setMaxChannelCount(%i)", count); qDebug("QSctpSocket::setMaximumChannelCount(%i)", count);
#endif #endif
d->maxChannelCount = qMax(count, -1); d->maximumChannelCount = qMax(count, -1);
} }
/*! /*!
@ -443,22 +443,22 @@ void QSctpSocket::setMaxChannelCount(int count)
Returns -1 if QSctpSocket is running in continuous byte stream Returns -1 if QSctpSocket is running in continuous byte stream
mode. mode.
\sa setMaxChannelCount(), readChannelCount(), writeChannelCount() \sa setMaximumChannelCount(), readChannelCount(), writeChannelCount()
*/ */
int QSctpSocket::maxChannelCount() const int QSctpSocket::maximumChannelCount() const
{ {
return d_func()->maxChannelCount; return d_func()->maximumChannelCount;
} }
/*! /*!
Returns \c true if the socket is running in datagram mode. Returns \c true if the socket is running in datagram mode.
\sa setMaxChannelCount() \sa setMaximumChannelCount()
*/ */
bool QSctpSocket::inDatagramMode() const bool QSctpSocket::isInDatagramMode() const
{ {
Q_D(const QSctpSocket); Q_D(const QSctpSocket);
return d->maxChannelCount != -1 && d->isBuffered; return d->maximumChannelCount != -1 && d->isBuffered;
} }
/*! /*!
@ -471,13 +471,13 @@ bool QSctpSocket::inDatagramMode() const
On failure, returns a QNetworkDatagram that reports \l On failure, returns a QNetworkDatagram that reports \l
{QNetworkDatagram::isValid()}{not valid}. {QNetworkDatagram::isValid()}{not valid}.
\sa writeDatagram(), inDatagramMode(), currentReadChannel() \sa writeDatagram(), isInDatagramMode(), currentReadChannel()
*/ */
QNetworkDatagram QSctpSocket::readDatagram() QNetworkDatagram QSctpSocket::readDatagram()
{ {
Q_D(QSctpSocket); Q_D(QSctpSocket);
if (!isReadable() || !inDatagramMode()) { if (!isReadable() || !isInDatagramMode()) {
qWarning("QSctpSocket::readDatagram(): operation is not permitted"); qWarning("QSctpSocket::readDatagram(): operation is not permitted");
return QNetworkDatagram(); return QNetworkDatagram();
} }
@ -507,14 +507,14 @@ QNetworkDatagram QSctpSocket::readDatagram()
Writes a \a datagram to the buffer of the current write channel. Writes a \a datagram to the buffer of the current write channel.
Returns true on success; otherwise returns false. Returns true on success; otherwise returns false.
\sa readDatagram(), inDatagramMode(), currentWriteChannel() \sa readDatagram(), isInDatagramMode(), currentWriteChannel()
*/ */
bool QSctpSocket::writeDatagram(const QNetworkDatagram &datagram) bool QSctpSocket::writeDatagram(const QNetworkDatagram &datagram)
{ {
Q_D(QSctpSocket); Q_D(QSctpSocket);
if (!isWritable() || d->state != QAbstractSocket::ConnectedState || !d->socketEngine if (!isWritable() || d->state != QAbstractSocket::ConnectedState || !d->socketEngine
|| !d->socketEngine->isValid() || !inDatagramMode()) { || !d->socketEngine->isValid() || !isInDatagramMode()) {
qWarning("QSctpSocket::writeDatagram(): operation is not permitted"); qWarning("QSctpSocket::writeDatagram(): operation is not permitted");
return false; return false;
} }

View File

@ -59,9 +59,9 @@ public:
void close() Q_DECL_OVERRIDE; void close() Q_DECL_OVERRIDE;
void disconnectFromHost() Q_DECL_OVERRIDE; void disconnectFromHost() Q_DECL_OVERRIDE;
void setMaxChannelCount(int count); void setMaximumChannelCount(int count);
int maxChannelCount() const; int maximumChannelCount() const;
bool inDatagramMode() const; bool isInDatagramMode() const;
QNetworkDatagram readDatagram(); QNetworkDatagram readDatagram();
bool writeDatagram(const QNetworkDatagram &datagram); bool writeDatagram(const QNetworkDatagram &datagram);

View File

@ -74,7 +74,7 @@ public:
bool writeToSocket() Q_DECL_OVERRIDE; bool writeToSocket() Q_DECL_OVERRIDE;
QByteArray incomingDatagram; QByteArray incomingDatagram;
int maxChannelCount; int maximumChannelCount;
typedef std::deque<QIpPacketHeader> IpHeaderList; typedef std::deque<QIpPacketHeader> IpHeaderList;
QVector<IpHeaderList> readHeaders; QVector<IpHeaderList> readHeaders;

View File

@ -112,7 +112,7 @@ void tst_QSctpSocket::constructing()
QVERIFY(!socket.isOpen()); QVERIFY(!socket.isOpen());
QVERIFY(!socket.isValid()); QVERIFY(!socket.isValid());
QCOMPARE(socket.socketType(), QAbstractSocket::SctpSocket); QCOMPARE(socket.socketType(), QAbstractSocket::SctpSocket);
QCOMPARE(socket.maxChannelCount(), 0); QCOMPARE(socket.maximumChannelCount(), 0);
QCOMPARE(socket.readChannelCount(), 0); QCOMPARE(socket.readChannelCount(), 0);
QCOMPARE(socket.writeChannelCount(), 0); QCOMPARE(socket.writeChannelCount(), 0);
@ -202,7 +202,7 @@ void tst_QSctpSocket::setSocketDescriptor()
{ {
QSctpServer server; QSctpServer server;
server.setMaxChannelCount(16); server.setMaximumChannelCount(16);
QVERIFY(server.listen()); QVERIFY(server.listen());
SOCKET sock = ::socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); SOCKET sock = ::socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
@ -218,8 +218,8 @@ void tst_QSctpSocket::setSocketDescriptor()
QVERIFY(socket.waitForConnected(3000)); QVERIFY(socket.waitForConnected(3000));
QVERIFY(server.waitForNewConnection(3000)); QVERIFY(server.waitForNewConnection(3000));
QCOMPARE(socket.readChannelCount(), server.maxChannelCount()); QCOMPARE(socket.readChannelCount(), server.maximumChannelCount());
QVERIFY(socket.writeChannelCount() <= server.maxChannelCount()); QVERIFY(socket.writeChannelCount() <= server.maximumChannelCount());
QSctpSocket *acceptedSocket = server.nextPendingDatagramConnection(); QSctpSocket *acceptedSocket = server.nextPendingDatagramConnection();
QVERIFY(acceptedSocket); QVERIFY(acceptedSocket);
@ -338,11 +338,11 @@ void tst_QSctpSocket::loop()
QSctpServer server; QSctpServer server;
server.setMaxChannelCount(10); server.setMaximumChannelCount(10);
QVERIFY(server.listen()); QVERIFY(server.listen());
QSctpSocket peter; QSctpSocket peter;
peter.setMaxChannelCount(10); peter.setMaximumChannelCount(10);
peter.connectToHost(QHostAddress::LocalHost, server.serverPort()); peter.connectToHost(QHostAddress::LocalHost, server.serverPort());
QVERIFY(peter.waitForConnected(3000)); QVERIFY(peter.waitForConnected(3000));
@ -389,11 +389,11 @@ void tst_QSctpSocket::loopInTCPMode()
QSctpServer server; QSctpServer server;
server.setMaxChannelCount(-1); server.setMaximumChannelCount(-1);
QVERIFY(server.listen()); QVERIFY(server.listen());
QSctpSocket peter; QSctpSocket peter;
peter.setMaxChannelCount(-1); peter.setMaximumChannelCount(-1);
peter.connectToHost(QHostAddress::LocalHost, server.serverPort()); peter.connectToHost(QHostAddress::LocalHost, server.serverPort());
QVERIFY(peter.waitForConnected(3000)); QVERIFY(peter.waitForConnected(3000));
QVERIFY(server.waitForNewConnection(3000)); QVERIFY(server.waitForNewConnection(3000));