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

source code of qtbase/src/network/kernel/qnetworkdatagram.h