1 | // Copyright (C) 2016 The Qt Company Ltd. |
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 QUDPSOCKET_H |
5 | #define QUDPSOCKET_H |
6 | |
7 | #include <QtNetwork/qtnetworkglobal.h> |
8 | #include <QtNetwork/qabstractsocket.h> |
9 | #include <QtNetwork/qhostaddress.h> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | |
14 | #ifndef QT_NO_UDPSOCKET |
15 | |
16 | class QNetworkDatagram; |
17 | class QNetworkInterface; |
18 | class QUdpSocketPrivate; |
19 | |
20 | class Q_NETWORK_EXPORT QUdpSocket : public QAbstractSocket |
21 | { |
22 | Q_OBJECT |
23 | public: |
24 | explicit QUdpSocket(QObject *parent = nullptr); |
25 | virtual ~QUdpSocket(); |
26 | |
27 | #if QT_VERSION < QT_VERSION_CHECK(7,0,0) && !defined(Q_QDOC) |
28 | // ### Qt7: move into QAbstractSocket |
29 | using QAbstractSocket::bind; |
30 | bool bind(QHostAddress::SpecialAddress addr, quint16 port = 0, BindMode mode = DefaultForPlatform) |
31 | { return bind(address: QHostAddress(addr), port, mode); } |
32 | #endif |
33 | |
34 | #ifndef QT_NO_NETWORKINTERFACE |
35 | bool joinMulticastGroup(const QHostAddress &groupAddress); |
36 | bool joinMulticastGroup(const QHostAddress &groupAddress, |
37 | const QNetworkInterface &iface); |
38 | bool leaveMulticastGroup(const QHostAddress &groupAddress); |
39 | bool leaveMulticastGroup(const QHostAddress &groupAddress, |
40 | const QNetworkInterface &iface); |
41 | |
42 | QNetworkInterface multicastInterface() const; |
43 | void setMulticastInterface(const QNetworkInterface &iface); |
44 | #endif |
45 | |
46 | bool hasPendingDatagrams() const; |
47 | qint64 pendingDatagramSize() const; |
48 | QNetworkDatagram receiveDatagram(qint64 maxSize = -1); |
49 | qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *host = nullptr, quint16 *port = nullptr); |
50 | |
51 | qint64 writeDatagram(const QNetworkDatagram &datagram); |
52 | qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &host, quint16 port); |
53 | inline qint64 writeDatagram(const QByteArray &datagram, const QHostAddress &host, quint16 port) |
54 | { return writeDatagram(data: datagram.constData(), len: datagram.size(), host, port); } |
55 | |
56 | private: |
57 | Q_DISABLE_COPY_MOVE(QUdpSocket) |
58 | Q_DECLARE_PRIVATE(QUdpSocket) |
59 | }; |
60 | |
61 | #endif // QT_NO_UDPSOCKET |
62 | |
63 | QT_END_NAMESPACE |
64 | |
65 | #endif // QUDPSOCKET_H |
66 | |