diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/network/socket/qabstractsocketengine_p.h | 11 | ||||
-rw-r--r-- | src/network/socket/qudpsocket.cpp | 43 |
2 files changed, 53 insertions, 1 deletions
diff --git a/src/network/socket/qabstractsocketengine_p.h b/src/network/socket/qabstractsocketengine_p.h index 3669852..9a2a7c3 100644 --- a/src/network/socket/qabstractsocketengine_p.h +++ b/src/network/socket/qabstractsocketengine_p.h @@ -61,6 +61,7 @@ QT_BEGIN_NAMESPACE class QAuthenticator; class QAbstractSocketEnginePrivate; +class QNetworkInterface; class QNetworkProxy; class QAbstractSocketEngineReceiver { @@ -94,7 +95,8 @@ public: BindExclusively, ReceiveOutOfBandData, LowDelayOption, - KeepAliveOption + KeepAliveOption, + MulticastLoopback }; virtual bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol) = 0; @@ -118,6 +120,13 @@ public: virtual qint64 write(const char *data, qint64 len) = 0; #ifndef QT_NO_UDPSOCKET + virtual bool joinMulticastGroup(const QHostAddress &groupAddress, + const QHostAddress &sourceAddress, + const QNetworkInterface &interface) = 0; + virtual bool leaveMulticastGroup(const QHostAddress &groupAddress, + const QHostAddress &sourceAddress, + const QNetworkInterface &interface) = 0; + virtual qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr = 0, quint16 *port = 0) = 0; virtual qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr, diff --git a/src/network/socket/qudpsocket.cpp b/src/network/socket/qudpsocket.cpp index d5366d3..4fc88dc 100644 --- a/src/network/socket/qudpsocket.cpp +++ b/src/network/socket/qudpsocket.cpp @@ -145,6 +145,7 @@ */ #include "qhostaddress.h" +#include "qnetworkinterface.h" #include "qabstractsocket_p.h" #include "qudpsocket.h" @@ -329,6 +330,48 @@ bool QUdpSocket::bind(quint16 port, BindMode mode) } /*! + \since 4.6 +*/ +bool QUdpSocket::joinMulticastGroup(const QHostAddress &groupAddress, MulticastMode mode) +{ + return joinMulticastGroup(groupAddress, QHostAddress::Any, QNetworkInterface(), mode); +} + +/*! + \since 4.6 + \overload +*/ +bool QUdpSocket::joinMulticastGroup(const QHostAddress &groupAddress, + const QHostAddress &sourceAddress, + const QNetworkInterface &interface, + MulticastMode mode) +{ + Q_D(QUdpSocket); + d->socketEngine->setOption(QAbstractSocketEngine::MulticastLoopback, + (mode & MulticastLoopback) ? 1 : 0); + return d->socketEngine->joinMulticastGroup(groupAddress, sourceAddress, interface); +} + +/*! + \since 4.6 +*/ +bool QUdpSocket::leaveMulticastGroup(const QHostAddress &groupAddress) +{ + return leaveMulticastGroup(groupAddress, QHostAddress::Any, QNetworkInterface()); +} + +/*! + \since 4.6 + \overload +*/ +bool QUdpSocket::leaveMulticastGroup(const QHostAddress &groupAddress, + const QHostAddress &sourceAddress, + const QNetworkInterface &interface) +{ + return d_func()->socketEngine->leaveMulticastGroup(groupAddress, sourceAddress, interface); +} + +/*! Returns true if at least one datagram is waiting to be read; otherwise returns false. |