diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-26 16:50:42 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-26 16:50:42 +0200 |
commit | 350824b0ecacabab7c7bb565df165d8c108ea43f (patch) | |
tree | 90ddd063b4d87470a85236623b33faeb1cbf8f10 /examples/imapresource | |
parent | 9450bcb17d9633e56bf43242463583ae9c0c53e9 (diff) | |
download | sink-350824b0ecacabab7c7bb565df165d8c108ea43f.tar.gz sink-350824b0ecacabab7c7bb565df165d8c108ea43f.zip |
Only create one session
And not one for every imap proxy
Diffstat (limited to 'examples/imapresource')
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 22 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.h | 7 |
2 files changed, 21 insertions, 8 deletions
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<void> runJob(KJob *job) | |||
99 | }); | 99 | }); |
100 | } | 100 | } |
101 | 101 | ||
102 | ImapServerProxy::ImapServerProxy(const QString &serverUrl, int port, SessionCache *sessionCache) : mSession(new KIMAP2::Session(serverUrl, qint16(port))), mSessionCache(sessionCache) | 102 | KIMAP2::Session *createNewSession(const QString &serverUrl, int port) |
103 | { | 103 | { |
104 | QObject::connect(mSession, &KIMAP2::Session::sslErrors, [this](const QList<QSslError> &errors) { | 104 | auto newSession = new KIMAP2::Session(serverUrl, qint16(port)); |
105 | if (Sink::Test::testModeEnabled()) { | ||
106 | newSession->setTimeout(1); | ||
107 | } else { | ||
108 | newSession->setTimeout(40); | ||
109 | } | ||
110 | QObject::connect(newSession, &KIMAP2::Session::sslErrors, [=](const QList<QSslError> &errors) { | ||
105 | SinkLog() << "Received ssl error: " << errors; | 111 | SinkLog() << "Received ssl error: " << errors; |
106 | mSession->ignoreErrors(errors); | 112 | newSession->ignoreErrors(errors); |
107 | }); | 113 | }); |
114 | return newSession; | ||
115 | } | ||
108 | 116 | ||
109 | if (Sink::Test::testModeEnabled()) { | 117 | ImapServerProxy::ImapServerProxy(const QString &serverUrl, int port, SessionCache *sessionCache) : mSessionCache(sessionCache), mSession(nullptr) |
110 | mSession->setTimeout(1); | 118 | { |
111 | } else { | 119 | if (!mSessionCache || mSessionCache->isEmpty()) { |
112 | mSession->setTimeout(40); | 120 | mSession = createNewSession(serverUrl, port); |
113 | } | 121 | } |
114 | } | 122 | } |
115 | 123 | ||
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: | |||
231 | return session; | 231 | return session; |
232 | } | 232 | } |
233 | } | 233 | } |
234 | return CachedSession{}; | 234 | return {}; |
235 | } | ||
236 | |||
237 | bool isEmpty() const | ||
238 | { | ||
239 | return mSessions.isEmpty(); | ||
235 | } | 240 | } |
236 | private: | 241 | private: |
237 | QList<CachedSession> mSessions; | 242 | QList<CachedSession> mSessions; |