| 1 | // Copyright (C) 2016 Intel Corporation. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #ifndef QNETWORKDATAGRAM_H |
| 6 | #define QNETWORKDATAGRAM_H |
| 7 | |
| 8 | #include <QtCore/qbytearray.h> |
| 9 | #include <QtNetwork/qhostaddress.h> |
| 10 | |
| 11 | #ifndef QT_NO_UDPSOCKET |
| 12 | |
| 13 | QT_BEGIN_NAMESPACE |
| 14 | |
| 15 | class QNetworkDatagramPrivate; |
| 16 | class QUdpSocketPrivate; |
| 17 | |
| 18 | class Q_NETWORK_EXPORT QNetworkDatagram |
| 19 | { |
| 20 | public: |
| 21 | QNetworkDatagram(); |
| 22 | QNetworkDatagram(const QByteArray &data, const QHostAddress &destinationAddress = QHostAddress(), |
| 23 | quint16 port = 0); // implicit |
| 24 | QNetworkDatagram(const QNetworkDatagram &other); |
| 25 | QNetworkDatagram &operator=(const QNetworkDatagram &other); |
| 26 | ~QNetworkDatagram() |
| 27 | { if (d) destroy(d); } |
| 28 | |
| 29 | QNetworkDatagram(QNetworkDatagram &&other) noexcept |
| 30 | : d(other.d) |
| 31 | { other.d = nullptr; } |
| 32 | QNetworkDatagram &operator=(QNetworkDatagram &&other) noexcept |
| 33 | { swap(other); return *this; } |
| 34 | |
| 35 | void swap(QNetworkDatagram &other) noexcept |
| 36 | { qt_ptr_swap(lhs&: d, rhs&: other.d); } |
| 37 | |
| 38 | void clear(); |
| 39 | bool isValid() const; |
| 40 | bool isNull() const |
| 41 | { return !isValid(); } |
| 42 | |
| 43 | uint interfaceIndex() const; |
| 44 | void setInterfaceIndex(uint index); |
| 45 | |
| 46 | QHostAddress senderAddress() const; |
| 47 | QHostAddress destinationAddress() const; |
| 48 | int senderPort() const; |
| 49 | int destinationPort() const; |
| 50 | void setSender(const QHostAddress &address, quint16 port = 0); |
| 51 | void setDestination(const QHostAddress &address, quint16 port); |
| 52 | |
| 53 | int hopLimit() const; |
| 54 | void setHopLimit(int count); |
| 55 | |
| 56 | QByteArray data() const; |
| 57 | void setData(const QByteArray &data); |
| 58 | |
| 59 | #if defined(Q_COMPILER_REF_QUALIFIERS) || defined(Q_QDOC) |
| 60 | QNetworkDatagram makeReply(const QByteArray &payload) const & |
| 61 | { return makeReply_helper(data: payload); } |
| 62 | QNetworkDatagram makeReply(const QByteArray &payload) && |
| 63 | { makeReply_helper_inplace(data: payload); return *this; } |
| 64 | #else |
| 65 | QNetworkDatagram makeReply(const QByteArray &paylaod) const |
| 66 | { return makeReply_helper(paylaod); } |
| 67 | #endif |
| 68 | |
| 69 | private: |
| 70 | QNetworkDatagramPrivate *d; |
| 71 | friend class QUdpSocket; |
| 72 | friend class QSctpSocket; |
| 73 | |
| 74 | explicit QNetworkDatagram(QNetworkDatagramPrivate &dd); |
| 75 | QNetworkDatagram makeReply_helper(const QByteArray &data) const; |
| 76 | void makeReply_helper_inplace(const QByteArray &data); |
| 77 | static void destroy(QNetworkDatagramPrivate *d); |
| 78 | }; |
| 79 | |
| 80 | Q_DECLARE_SHARED(QNetworkDatagram) |
| 81 | |
| 82 | QT_END_NAMESPACE |
| 83 | |
| 84 | QT_DECL_METATYPE_EXTERN(QNetworkDatagram, Q_NETWORK_EXPORT) |
| 85 | |
| 86 | #endif // QT_NO_UDPSOCKET |
| 87 | |
| 88 | #endif // QNETWORKDATAGRAM_H |
| 89 |
