diff options
Diffstat (limited to 'src/coap/qcoapclient.cpp')
-rw-r--r-- | src/coap/qcoapclient.cpp | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/coap/qcoapclient.cpp b/src/coap/qcoapclient.cpp index 5469ef2..dc02464 100644 --- a/src/coap/qcoapclient.cpp +++ b/src/coap/qcoapclient.cpp @@ -162,16 +162,8 @@ QCoapClientPrivate::~QCoapClientPrivate() constructors. */ QCoapClient::QCoapClient(QtCoap::SecurityMode securityMode, QObject *parent) : - QCoapClient(new QCoapQUdpConnection(securityMode), parent) -{ -} - -/*! - Constructs a QCoapClient object with the given \a connection and - sets \a parent as the parent object. -*/ -QCoapClient::QCoapClient(QCoapConnection *connection, QObject *parent) : - QObject(*new QCoapClientPrivate(new QCoapProtocol, connection), parent) + QObject(*new QCoapClientPrivate(new QCoapProtocol, new QCoapQUdpConnection(securityMode)), + parent) { Q_D(QCoapClient); @@ -210,6 +202,28 @@ QCoapClient::QCoapClient(QCoapConnection *connection, QObject *parent) : } /*! + \internal + + Sets the client's connection to \a customConnection. +*/ +void QCoapClientPrivate::setConnection(QCoapConnection *customConnection) +{ + Q_Q(QCoapClient); + + delete connection; + connection = customConnection; + + q->connect(connection, &QCoapConnection::readyRead, protocol, + [this](const QByteArray &data, const QHostAddress &sender) { + protocol->d_func()->onFrameReceived(data, sender); + }); + q->connect(connection, &QCoapConnection::error, protocol, + [this](QAbstractSocket::SocketError socketError) { + protocol->d_func()->onConnectionError(socketError); + }); +} + +/*! Destroys the QCoapClient object and frees up any resources. Note that QCoapReply objects that are returned from this class have the QCoapClient set as their parents, which means that @@ -676,4 +690,16 @@ void QCoapClient::setMaximumRetransmitCount(uint maximumRetransmitCount) Q_ARG(uint, maximumRetransmitCount)); } +/*! + Sets the minimum token size to \a tokenSize in bytes. For security reasons it is + recommended to use tokens with a length of at least 4 bytes. The default value for + this parameter is 4 bytes. +*/ +void QCoapClient::setMinimumTokenSize(int tokenSize) +{ + Q_D(QCoapClient); + QMetaObject::invokeMethod(d->protocol, "setMinimumTokenSize", Qt::QueuedConnection, + Q_ARG(int, tokenSize)); +} + QT_END_NAMESPACE |