From 7fdd62dad9bbbeaf2d6577f504704e9f1f51477a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 27 Jun 2018 13:54:50 +0200 Subject: Prevent a recycled session from timing out immediately. This seems to happen sometimes (showed up in tests), and causes operations to fail. --- examples/imapresource/imapserverproxy.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index ce379de..918a21a 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp @@ -129,14 +129,18 @@ static KAsync::Job runJob(KJob *job) }); } -KIMAP2::Session *createNewSession(const QString &serverUrl, int port) +static int socketTimeout() { - auto newSession = new KIMAP2::Session(serverUrl, qint16(port)); if (Sink::Test::testModeEnabled()) { - newSession->setTimeout(1); - } else { - newSession->setTimeout(40); + return 1; } + return 40; +} + +KIMAP2::Session *createNewSession(const QString &serverUrl, int port) +{ + auto newSession = new KIMAP2::Session(serverUrl, qint16(port)); + newSession->setTimeout(socketTimeout()); QObject::connect(newSession, &KIMAP2::Session::sslErrors, [=](const QList &errors) { SinkLog() << "Received ssl error: " << errors; newSession->ignoreErrors(errors); @@ -173,6 +177,8 @@ KAsync::Job ImapServerProxy::login(const QString &username, const QString } Q_ASSERT(mSession); if (mSession->state() == KIMAP2::Session::Authenticated || mSession->state() == KIMAP2::Session::Selected) { + //Prevent the socket from timing out right away, right here (otherwise it just might time out right before we were able to start the job) + mSession->setTimeout(socketTimeout()); SinkLog() << "Reusing existing session."; return KAsync::null(); } -- cgit v1.2.3