From 350824b0ecacabab7c7bb565df165d8c108ea43f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 26 Apr 2017 16:50:42 +0200 Subject: Only create one session And not one for every imap proxy --- examples/imapresource/imapserverproxy.cpp | 22 +++++++++++++++------- examples/imapresource/imapserverproxy.h | 7 ++++++- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index d3ad2d4..7fa0b5a 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp @@ -99,17 +99,25 @@ static KAsync::Job runJob(KJob *job) }); } -ImapServerProxy::ImapServerProxy(const QString &serverUrl, int port, SessionCache *sessionCache) : mSession(new KIMAP2::Session(serverUrl, qint16(port))), mSessionCache(sessionCache) +KIMAP2::Session *createNewSession(const QString &serverUrl, int port) { - QObject::connect(mSession, &KIMAP2::Session::sslErrors, [this](const QList &errors) { + auto newSession = new KIMAP2::Session(serverUrl, qint16(port)); + if (Sink::Test::testModeEnabled()) { + newSession->setTimeout(1); + } else { + newSession->setTimeout(40); + } + QObject::connect(newSession, &KIMAP2::Session::sslErrors, [=](const QList &errors) { SinkLog() << "Received ssl error: " << errors; - mSession->ignoreErrors(errors); + newSession->ignoreErrors(errors); }); + return newSession; +} - if (Sink::Test::testModeEnabled()) { - mSession->setTimeout(1); - } else { - mSession->setTimeout(40); +ImapServerProxy::ImapServerProxy(const QString &serverUrl, int port, SessionCache *sessionCache) : mSessionCache(sessionCache), mSession(nullptr) +{ + if (!mSessionCache || mSessionCache->isEmpty()) { + mSession = createNewSession(serverUrl, port); } } diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h index 2d90f39..82f4f58 100644 --- a/examples/imapresource/imapserverproxy.h +++ b/examples/imapresource/imapserverproxy.h @@ -231,7 +231,12 @@ public: return session; } } - return CachedSession{}; + return {}; + } + + bool isEmpty() const + { + return mSessions.isEmpty(); } private: QList mSessions; -- cgit v1.2.3