diff options
author | Damien Caliste <dcaliste@free.fr> | 2025-02-21 15:40:06 +0100 |
---|---|---|
committer | Damien Caliste <dcaliste@free.fr> | 2025-02-28 09:18:40 +0100 |
commit | db1dda15e632983962cbd76b646ed8cb72cb1f35 (patch) | |
tree | 6ae23e5c39353d1b4fa0094bd10aa25e2cde01af | |
parent | c50c752313a75f3f473a0e6c08e7207d42b88a7f (diff) |
Synchronize idle renewal timers
Use a common QTimer in ImapClient for every
IdleProtocol, so the network accesses to renew
the idling connections are all done in a close-
by period of time, allowing the radio to sleep
for a longer time between wakes-up.
Change-Id: I7c9378a0af74015a34fd6cc98fa9517433d28392
Reviewed-by: Pekka Vuorela <pvuorela@iki.fi>
-rw-r--r-- | src/plugins/messageservices/imap/imapclient.cpp | 28 | ||||
-rw-r--r-- | src/plugins/messageservices/imap/imapclient.h | 2 |
2 files changed, 20 insertions, 10 deletions
diff --git a/src/plugins/messageservices/imap/imapclient.cpp b/src/plugins/messageservices/imap/imapclient.cpp index e389b31a..4d093548 100644 --- a/src/plugins/messageservices/imap/imapclient.cpp +++ b/src/plugins/messageservices/imap/imapclient.cpp @@ -190,7 +190,7 @@ signals: protected slots: virtual void idleContinuation(ImapCommand, const QString &); virtual void idleCommandTransition(ImapCommand, OperationStatus); - virtual void idleTimeOut(); + virtual void idleRenew(); virtual void idleTransportError(); virtual void idleErrorRecovery(); void logIn(); @@ -201,7 +201,6 @@ protected: QMailFolder _folder; private: - QTimer _idleTimer; // Send a DONE command every 29 minutes QTimer _idleRecoveryTimer; // Check command hasn't hung QMailCredentialsInterface *_credentials; }; @@ -222,9 +221,6 @@ IdleProtocol::IdleProtocol(ImapClient *client, const QMailFolder &folder, QMailC connect(_client, SIGNAL(sessionError()), this, SLOT(idleTransportError()) ); - _idleTimer.setSingleShot(true); - connect(&_idleTimer, SIGNAL(timeout()), - this, SLOT(idleTimeOut())); _idleRecoveryTimer.setSingleShot(true); connect(&_idleRecoveryTimer, SIGNAL(timeout()), this, SLOT(idleErrorRecovery())); @@ -271,15 +267,14 @@ void IdleProtocol::onCredentialsStatusChanged() void IdleProtocol::idleContinuation(ImapCommand command, const QString &type) { - const int idleTimeout = 28*60*1000; - if (command == IMAP_Idle) { if (type == QString("idling")) { qMailLog(IMAP) << objectName() << "IDLE: Idle connection established."; // We are now idling - _idleTimer.start(idleTimeout); _idleRecoveryTimer.stop(); + connect(_client, &ImapClient::renewPushEmail, + this, &IdleProtocol::idleRenew); _client->setIdlingForFolder(_folder.id()); } else if (type == QString("newmail")) { @@ -379,10 +374,11 @@ void IdleProtocol::idleCommandTransition(const ImapCommand command, const Operat } } -void IdleProtocol::idleTimeOut() +void IdleProtocol::idleRenew() { _idleRecoveryTimer.start(_client->idleRetryDelay()*1000); // Detect an unresponsive server - _idleTimer.stop(); + disconnect(_client, &ImapClient::renewPushEmail, + this, &IdleProtocol::idleRenew); sendIdleDone(); } @@ -469,6 +465,10 @@ ImapClient::ImapClient(const QMailAccountId &id, QObject* parent) connect(&_inactiveTimer, SIGNAL(timeout()), this, SLOT(connectionInactive())); + _idleTimer.setSingleShot(true); + _idleTimer.setInterval(28 * 60 * 1000); + connect(&_idleTimer, &QTimer::timeout, this, &ImapClient::renewPushEmail); + connect(QMailMessageBuffer::instance(), SIGNAL(flushed()), this, SLOT(messageBufferFlushed())); setupAccount(); @@ -1691,6 +1691,10 @@ bool ImapClient::isPushEmailEstablished() void ImapClient::setIdlingForFolder(const QMailFolderId &id) { _waitingForIdleFolderIds.removeOne(id); + if (_monitored.value(id)->connected() + && !_idleTimer.isActive()) { + _idleTimer.start(); + } if (_waitingForIdleFolderIds.isEmpty()) { _idleRetryDelay = InitialIdleRetryDelay; commandCompleted(IMAP_Idle_Continuation, OpOk); @@ -1717,6 +1721,10 @@ void ImapClient::monitor(const QMailFolderIdList &mailboxIds) { static int count(0); + if (mailboxIds.isEmpty()) { + _idleTimer.stop(); + } + foreach(const QMailFolderId &id, _monitored.keys()) { if (!mailboxIds.contains(id)) { qMailLog(IMAP) << "stop monitoring folder" << id; diff --git a/src/plugins/messageservices/imap/imapclient.h b/src/plugins/messageservices/imap/imapclient.h index 900fb94f..460ae5e4 100644 --- a/src/plugins/messageservices/imap/imapclient.h +++ b/src/plugins/messageservices/imap/imapclient.h @@ -98,6 +98,7 @@ signals: void errorOccurred(QMailServiceAction::Status::ErrorCode, const QString &); void updateStatus(const QString &); void restartPushEmail(); + void renewPushEmail(); void progressChanged(uint, uint); void retrievalCompleted(); @@ -170,6 +171,7 @@ private: bool _qresyncEnabled; bool _requestRapidClose; bool _rapidClosing; + QTimer _idleTimer; int _idleRetryDelay; // Try to restablish IDLE state enum IdleRetryDelay { InitialIdleRetryDelay = 30 }; //seconds |