169 #ifndef QT_NO_UDPSOCKET 171 #define QT_CHECK_BOUND(function, a) do { \ 173 qWarning(function" called on a QUdpSocket when not in QUdpSocket::BoundState"); \ 197 address = &remoteAddress;
201 #if defined(QT_NO_IPV6) 205 q->setErrorString(
QUdpSocket::tr(
"This platform does not support IPv6"));
230 d_func()->isBuffered =
false;
258 if (!
d->ensureInitialized(address, port))
261 bool result = d_func()->socketEngine->bind(address, port);
262 d->cachedSocketDescriptor =
d->socketEngine->socketDescriptor();
265 d->socketError = d_func()->socketEngine->error();
272 d->localAddress =
d->socketEngine->localAddress();
273 d->localPort =
d->socketEngine->localPort();
276 d_func()->socketEngine->setReadNotificationEnabled(
true);
292 if (!
d->ensureInitialized(address, port))
311 bool result = d_func()->socketEngine->bind(address, port);
312 d->cachedSocketDescriptor =
d->socketEngine->socketDescriptor();
315 d->socketError = d_func()->socketEngine->error();
322 d->localAddress =
d->socketEngine->localAddress();
323 d->localPort =
d->socketEngine->localPort();
326 d_func()->socketEngine->setReadNotificationEnabled(
true);
356 #ifndef QT_NO_NETWORKINTERFACE 395 return d->socketEngine->joinMulticastGroup(groupAddress, iface);
434 return d_func()->socketEngine->leaveMulticastGroup(groupAddress, iface);
456 return d->socketEngine->multicastInterface();
476 qWarning(
"QUdpSocket::setMulticastInterface() called on a QUdpSocket when not in QUdpSocket::BoundState");
479 d->socketEngine->setMulticastInterface(iface);
482 #endif // QT_NO_NETWORKINTERFACE 493 return d_func()->socketEngine->hasPendingDatagrams();
505 return d_func()->socketEngine->pendingDatagramSize();
536 #if defined QUDPSOCKET_DEBUG 537 qDebug(
"QUdpSocket::writeDatagram(%p, %llu, \"%s\", %i)", data, size,
540 if (!
d->ensureInitialized(address))
543 qint64 sent =
d->socketEngine->writeDatagram(data, size, address, port);
544 d->cachedSocketDescriptor =
d->socketEngine->socketDescriptor();
549 d->socketError =
d->socketEngine->error();
588 #if defined QUDPSOCKET_DEBUG 589 qDebug(
"QUdpSocket::readDatagram(%p, %llu, %p, %p)", data, maxSize, address, port);
592 qint64 readBytes =
d->socketEngine->readDatagram(data, maxSize, address, port);
593 d_func()->socketEngine->setReadNotificationEnabled(
true);
595 d->socketError =
d->socketEngine->error();
601 #endif // QT_NO_UDPSOCKET
virtual ~QUdpSocket()
Destroys the socket, closing the connection if necessary.
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
The QUdpSocket class provides a UDP socket.
#define QT_END_NAMESPACE
This macro expands to.
QUdpSocket(QObject *parent=0)
Creates a QUdpSocket object.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
void bytesWritten(qint64 bytes)
This signal is emitted every time a payload of data has been written to the device.
NetworkLayerProtocol
This enum describes the network layer protocol values used in Qt.
bool hasPendingDatagrams() const
Returns true if at least one datagram is waiting to be read; otherwise returns false.
The QObject class is the base class of all Qt objects.
qint64 pendingDatagramSize() const
Returns the size of the first pending UDP datagram.
#define QT_CHECK_BOUND(function, a)
bool bind(const QHostAddress &address, quint16 port)
Binds this socket to the address address and the port port.
Q_CORE_EXPORT void qDebug(const char *,...)
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool ensureInitialized(const QHostAddress &bindAddress, quint16 bindPort)
Q_CORE_EXPORT void qWarning(const char *,...)
QAbstractSocket::SocketError socketError
static const char * data(const QByteArray &arr)
QString toString() const
Returns the address as a string.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
bool ensureInitialized(const QHostAddress &remoteAddress)
bool joinMulticastGroup(const QHostAddress &groupAddress)
Joins the the multicast group specified by groupAddress on the default interface chosen by the operat...
qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &host, quint16 port)
Sends the datagram at data of size size to the host address address at port port. ...
bool doEnsureInitialized(const QHostAddress &bindAddress, quint16 bindPort, const QHostAddress &remoteAddress)
const char * constData() const
Returns a pointer to the data stored in the byte array.
#define Q_DECLARE_PUBLIC(Class)
QAbstractSocket::NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
void setMulticastInterface(const QNetworkInterface &iface)
Sets the outgoing interface for multicast datagrams to the interface iface.
void setErrorString(const QString &errorString)
Sets the human readable description of the last device error that occurred to str.
QAbstractSocketEngine * socketEngine
QNetworkInterface multicastInterface() const
Returns the interface for the outgoing interface for multicast datagrams.
bool leaveMulticastGroup(const QHostAddress &groupAddress)
Leaves the multicast group specified by groupAddress on the default interface chosen by the operating...
void stateChanged(QAbstractSocket::SocketState)
This signal is emitted whenever QAbstractSocket's state changes.
bool initSocketLayer(QAbstractSocket::NetworkLayerProtocol protocol)
Initializes the socket layer to by of type type, using the network layer protocol protocol...
void resolveProxy(const QString &hostName, quint16 port)
Resolve the proxy to its final value.
virtual bool isValid() const =0
The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces...
The QHostAddress class provides an IP address.
SocketError error() const
Returns the type of error that last occurred.
The QAbstractSocket class provides the base functionality common to all socket types.
qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *host=0, quint16 *port=0)
Receives a datagram no larger than maxSize bytes and stores it in data.
SocketState state() const
Returns the state of the socket.
bool isValid() const
Returns true if the socket is valid and ready for use; otherwise returns false.