summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorAndrew Stanley-Jones <andrew.stanley-jones@nokia.com>2012-05-31 13:50:07 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-01 13:26:41 +0200
commitd959b89b873e67b68a55809cc09e09c726f45050 (patch)
treef43470b674bfdf74d782bcc8a415c61ac9315224 /src/tools
parent054f5b7784eb0e40c24ccef7bba4170a19862881 (diff)
Reconnect if the interface goes away
Multicast sockets don't tell us if the interface comes and goes. Poll and try to reconnect if we notice the interface is missing. Change-Id: I5c8542ec1d92b1fd59afd1069b7093d70cd80625 Reviewed-by: Alex Wilson <alex.wilson@nokia.com>
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/sfwlisten/main.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/tools/sfwlisten/main.cpp b/src/tools/sfwlisten/main.cpp
index 96c6e9aa..72b1262c 100644
--- a/src/tools/sfwlisten/main.cpp
+++ b/src/tools/sfwlisten/main.cpp
@@ -63,15 +63,19 @@ public:
SFWReceiver(const QString &intfFilter);
public slots:
- void makeSockets();
void socketReadyRead();
+ void socketVerify();
+ void makeSockets();
private:
QString intfFilter;
+ QTimer socketCheck;
+ QUdpSocket *socket;
};
SFWReceiver::SFWReceiver(const QString &intfFilter) : intfFilter(intfFilter)
{
+ connect(&socketCheck, SIGNAL(timeout()), this, SLOT(socketVerify()));
makeSockets();
}
@@ -89,7 +93,7 @@ void SFWReceiver::makeSockets()
|| intf.name().startsWith("tun") || intf.name().startsWith("tap"))
continue;
- QUdpSocket *socket = new QUdpSocket(this);
+ socket = new QUdpSocket(this);
printf("Trying interface %s ...", qPrintable(intf.name()));
if (!socket->bind(QHostAddress::AnyIPv4, 10520, QUdpSocket::ShareAddress)) {
printf("Couldn't bind: %s\n", qPrintable(socket->errorString()));
@@ -113,12 +117,36 @@ void SFWReceiver::makeSockets()
if (!gotone) {
QTimer::singleShot(200, this, SLOT(makeSockets()));
+ socketCheck.stop();
+ } else {
+ socketCheck.setInterval(1000);
+ socketCheck.start();
+ }
+}
+
+void SFWReceiver::socketVerify()
+{
+ QList<QNetworkInterface> intfs = QNetworkInterface::allInterfaces();
+ bool gotone = false;
+ QString name = socket->multicastInterface().name();
+
+ foreach (const QNetworkInterface &intf, intfs) {
+ if (intf.name() == name) {
+ gotone = true;
+ break;
+ }
+ }
+
+ if (!gotone) {
+ printf("Interface down...\n");
+ delete socket;
+ socket = 0;
+ makeSockets();
}
}
void SFWReceiver::socketReadyRead()
{
- QUdpSocket *socket = qobject_cast<QUdpSocket *>(sender());
QString intf = socket->multicastInterface().name();
while (socket->hasPendingDatagrams()) {