diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-05-05 14:20:06 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-09-01 12:24:36 (GMT) |
commit | e6b836293346d81c926bf17c5e9b128c969dc672 (patch) | |
tree | b601a25508275bcf4e24779cdd4bfaa12167fbaa /src | |
parent | acc7d0d4111916af4814f6521e5269e38c34e76f (diff) | |
download | Qt-e6b836293346d81c926bf17c5e9b128c969dc672.zip Qt-e6b836293346d81c926bf17c5e9b128c969dc672.tar.gz Qt-e6b836293346d81c926bf17c5e9b128c969dc672.tar.bz2 |
Implement QUdpSocket::joinMulticastGroup() and leaveMulticastGroup()
This is actually just done in the socket engine, so we need to add the
API for setting the loopback socket option and joining/leaving the
group. Implementation for the various engines will follow.
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. |