diff options
author | Fawzi Mohamed <fawzi.mohamed@nokia.com> | 2012-04-19 17:28:44 +0200 |
---|---|---|
committer | Fawzi Mohamed <fawzi.mohamed@nokia.com> | 2012-04-24 11:43:24 +0200 |
commit | cf4ecad4bc20f246e1c67047b158ac2fe799183b (patch) | |
tree | 1dde0d0e1aad0861614ffc0d70399242b486a968 | |
parent | 56908de4d541b0fb9a9a080e79314879c7d86fa6 (diff) | |
download | qt-creator-cf4ecad4bc20f246e1c67047b158ac2fe799183b.tar.gz |
zeroconf: quick startup if the embedded daemon is running
test if the embedded lib works before avahi, to avoid slow
startup on repeated startups when the avahi lib is present
but the daemon does not work.
Change-Id: I5c07ed3513c51065b2cb164e6131b7b85236acfd
Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
-rw-r--r-- | src/libs/zeroconf/embeddedLib.cpp | 2 | ||||
-rw-r--r-- | src/libs/zeroconf/servicebrowser.cpp | 20 | ||||
-rw-r--r-- | src/libs/zeroconf/servicebrowser_p.h | 2 |
3 files changed, 17 insertions, 7 deletions
diff --git a/src/libs/zeroconf/embeddedLib.cpp b/src/libs/zeroconf/embeddedLib.cpp index 929c8391bf..310c25e909 100644 --- a/src/libs/zeroconf/embeddedLib.cpp +++ b/src/libs/zeroconf/embeddedLib.cpp @@ -70,6 +70,8 @@ public: EmbeddedZConfLib(const QString &daemonPath, ZConfLib::Ptr fallBack) : ZConfLib(fallBack), daemonPath(daemonPath) { + if (daemonPath.isEmpty()) + m_maxErrors = 0; if (!daemonPath.isEmpty() && daemonPath.at(0) != '/' && daemonPath.at(0) != '.') this->daemonPath = QCoreApplication::applicationDirPath() + QChar('/') + daemonPath; } diff --git a/src/libs/zeroconf/servicebrowser.cpp b/src/libs/zeroconf/servicebrowser.cpp index b4c8b30a3e..ce02b88e41 100644 --- a/src/libs/zeroconf/servicebrowser.cpp +++ b/src/libs/zeroconf/servicebrowser.cpp @@ -153,9 +153,10 @@ Q_GLOBAL_STATIC(ZeroConfLib, zeroConfLibInstance) #endif ZeroConfLib::ZeroConfLib(): m_lock(QMutex::Recursive), - m_defaultLib(ZConfLib::createAvahiLib(QLatin1String("avahi-client"),QLatin1String("3"), - ZConfLib::createDnsSdLib(QLatin1String(defaultmDnsSdLibName), - ZConfLib::createEmbeddedLib(QLatin1String(defaultmDNSDaemonName))))) + m_defaultLib(ZConfLib::createDnsSdLib(QLatin1String(defaultmDnsSdLibName), + ZConfLib::createEmbeddedLib(QString(), + ZConfLib::createAvahiLib(QLatin1String("avahi-client"),QLatin1String("3"), + ZConfLib::createEmbeddedLib(QLatin1String(defaultmDNSDaemonName)))))) { qRegisterMetaType<ZeroConf::Service::ConstPtr>("ZeroConf::Service::ConstPtr"); qRegisterMetaType<ZeroConf::ErrorMessage::SeverityLevel>("ZeroConf::ErrorMessage::SeverityLevel"); @@ -1752,7 +1753,7 @@ void MainConnection::createConnection() appendError(ErrorMessage::WarningLevel, tr("MainConnection using lib %1 failed the initialization of mainRef with error %2") .arg(lib->name()).arg(error)); ++m_nErrs; - if (m_nErrs > 10 || !lib->isOk()) + if (m_nErrs > lib->maxErrors() || !lib->isOk()) abortLib(); } else { QList<ServiceBrowserPrivate *> waitingBrowsers; @@ -1772,7 +1773,7 @@ void MainConnection::createConnection() } else if (err == kDNSServiceErr_ServiceNotRunning) { appendError(ErrorMessage::WarningLevel, tr("MainConnection using lib %1 failed because no daemon is running") .arg(lib->name())); - if (m_nErrs > 5 || !lib->isOk()) { + if (m_nErrs > lib->maxErrors()/2 || !lib->isOk()) { abortLib(); } else if (lib->tryStartDaemon()) { ++m_nErrs; @@ -1791,7 +1792,7 @@ void MainConnection::createConnection() } if (status() < Stopping) appendError(ErrorMessage::NoteLevel, - tr("MainConncetion could sucessfully create a connection using lib %1") + tr("MainConnection could successfully create a connection using lib %1") .arg(lib->name())); } @@ -1940,7 +1941,7 @@ QString ZConfLib::name(){ return QString::fromLatin1("ZeroConfLib@%1").arg(size_t(this), 0, 16); } -ZConfLib::ZConfLib(ZConfLib::Ptr f) : fallbackLib(f), m_isOk(true) +ZConfLib::ZConfLib(ZConfLib::Ptr f) : fallbackLib(f), m_isOk(true), m_maxErrors(8) { } ZConfLib::~ZConfLib() @@ -1962,6 +1963,11 @@ void ZConfLib::setError(bool failure, const QString &eMsg) m_isOk = !failure; } +int ZConfLib::maxErrors() const +{ + return m_maxErrors; +} + ZConfLib::RunLoopStatus ZConfLib::processOneEvent(MainConnection *mainConnection, ConnectionRef cRef, qint64 maxMsBlock) { diff --git a/src/libs/zeroconf/servicebrowser_p.h b/src/libs/zeroconf/servicebrowser_p.h index da94ce58c0..d2c1624927 100644 --- a/src/libs/zeroconf/servicebrowser_p.h +++ b/src/libs/zeroconf/servicebrowser_p.h @@ -120,6 +120,7 @@ public: bool isOk(); QString errorMsg(); void setError(bool failure, const QString &eMsg); + int maxErrors() const; static Ptr createEmbeddedLib(const QString &daemonPath, const Ptr &fallback = Ptr(0)); static Ptr createDnsSdLib(const QString &libName, const Ptr &fallback = Ptr(0)); @@ -127,6 +128,7 @@ public: protected: bool m_isOk; QString m_errorMsg; + int m_maxErrors; }; /// class that gathers all needed info on a service, all its methods (creation included) are |