72#ifndef QT_NO_UDPSOCKET
74#define QT_CHECK_BOUND(function, a) do { \
76 qWarning(function" called on a QUdpSocket when not in QUdpSocket::BoundState"); \
88 {
return doEnsureInitialized(bindAddress, bindPort,
QHostAddress()); }
91 {
return doEnsureInitialized(
QHostAddress(), 0, remoteAddress); }
94bool QUdpSocketPrivate::doEnsureInitialized(
const QHostAddress &bindAddress,
quint16 bindPort,
124 d_func()->isBuffered =
false;
136#ifndef QT_NO_NETWORKINTERFACE
177 return d->socketEngine->joinMulticastGroup(groupAddress, iface);
216 return d_func()->socketEngine->leaveMulticastGroup(groupAddress, iface);
235 return d->socketEngine->multicastInterface();
252 qWarning(
"QUdpSocket::setMulticastInterface() called on a QUdpSocket when not in QUdpSocket::BoundState");
255 d->socketEngine->setMulticastInterface(iface);
269 return d_func()->socketEngine->hasPendingDatagrams();
281 return d_func()->socketEngine->pendingDatagramSize();
309#if defined QUDPSOCKET_DEBUG
310 qDebug(
"QUdpSocket::writeDatagram(%p, %llu, \"%s\", %i)",
data,
size,
319 d->cachedSocketDescriptor =
d->socketEngine->socketDescriptor();
327 tr(
"Unable to send a datagram"));
330 d->setErrorAndEmit(
d->socketEngine->error(),
d->socketEngine->errorString());
373#if defined QUDPSOCKET_DEBUG
374 qDebug(
"QUdpSocket::writeDatagram(%p, %i, \"%s\", %i)",
375 datagram.d->data.constData(),
376 datagram.d->data.size(),
377 datagram.destinationAddress().toString().toLatin1().constData(),
378 datagram.destinationPort());
385 qint64 sent =
d->socketEngine->writeDatagram(datagram.d->data.constData(),
386 datagram.d->data.size(),
388 d->cachedSocketDescriptor =
d->socketEngine->socketDescriptor();
393 d->setErrorAndEmit(
d->socketEngine->error(),
d->socketEngine->errorString());
419#if defined QUDPSOCKET_DEBUG
420 qDebug(
"QUdpSocket::receiveDatagram(%lld)", maxSize);
425 maxSize =
d->socketEngine->pendingDatagramSize();
430 qint64 readBytes =
d->socketEngine->readDatagram(
result.d->data.data(), maxSize, &
result.d->header,
432 d->hasPendingData =
false;
433 d->hasPendingDatagram =
false;
434 d->socketEngine->setReadNotificationEnabled(
true);
436 d->setErrorAndEmit(
d->socketEngine->error(),
d->socketEngine->errorString());
440 result.d->data.truncate(readBytes);
464#if defined QUDPSOCKET_DEBUG
472 readBytes =
d->socketEngine->readDatagram(
data, maxSize, &
header,
479 readBytes =
d->socketEngine->readDatagram(
data, maxSize);
482 d->hasPendingData =
false;
483 d->hasPendingDatagram =
false;
484 d->socketEngine->setReadNotificationEnabled(
true);
486 if (readBytes == -2) {
489 tr(
"No datagram available for reading"));
492 d->setErrorAndEmit(
d->socketEngine->error(),
d->socketEngine->errorString());
501#include "moc_qudpsocket.cpp"
virtual bool isValid() const =0
QAbstractSocketEngine * socketEngine
void resolveProxy(const QString &hostName, quint16 port)
bool initSocketLayer(QAbstractSocket::NetworkLayerProtocol protocol)
The QAbstractSocket class provides the base functionality common to all socket types.
virtual bool bind(const QHostAddress &address, quint16 port=0, BindMode mode=DefaultForPlatform)
static constexpr auto UnknownNetworkLayerProtocol
bool isValid() const
Returns true if the socket is valid and ready for use; otherwise returns false.
SocketState state() const
Returns the state of the socket.
The QHostAddress class provides an IP address.
QString toString() const
Returns the address as a string.
NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
The QNetworkDatagram class provides the data and metadata of a UDP datagram.
The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces.
bool ensureInitialized(const QHostAddress &bindAddress, quint16 bindPort)
bool ensureInitialized(const QHostAddress &remoteAddress)
bool leaveMulticastGroup(const QHostAddress &groupAddress)
bool joinMulticastGroup(const QHostAddress &groupAddress)
QNetworkDatagram receiveDatagram(qint64 maxSize=-1)
QNetworkInterface multicastInterface() const
bool hasPendingDatagrams() const
Returns true if at least one datagram is waiting to be read; otherwise returns false.
virtual ~QUdpSocket()
Destroys the socket, closing the connection if necessary.
qint64 writeDatagram(const QNetworkDatagram &datagram)
void setMulticastInterface(const QNetworkInterface &iface)
qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *host=nullptr, quint16 *port=nullptr)
Receives a datagram no larger than maxSize bytes and stores it in data.
qint64 pendingDatagramSize() const
Returns the size of the first pending UDP datagram.
QUdpSocket(QObject *parent=nullptr)
Creates a QUdpSocket object.
Combined button and popup list for selecting options.
constexpr Initialization Uninitialized
static QString header(const QString &name)
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
GLenum GLsizei GLuint GLint * bytesWritten
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLuint64EXT address
#define QT_CHECK_BOUND(function, a)