From dcb85ffa51a542a7c1164346fe17fc1ec2168ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 23 May 2013 00:43:16 +0200 Subject: [PATCH] IMAP: if connecting fails, try again a few times. * Also documented SyncCommand. --- .../imap/IMAPConnectionWorker.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPConnectionWorker.cpp b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPConnectionWorker.cpp index 7cdf655025..79ef13bf1e 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPConnectionWorker.cpp +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPConnectionWorker.cpp @@ -89,6 +89,10 @@ public: }; +/*! All commands that inherit from this class will automatically maintain the + worker's fSyncPending member, and will thus prevent syncing more than once + concurrently. +*/ class SyncCommand : public WorkerCommand { }; @@ -613,8 +617,19 @@ IMAPConnectionWorker::_Connect() if (fProtocol.IsConnected()) return B_OK; - status_t status = fProtocol.Connect(fSettings.ServerAddress(), - fSettings.Username(), fSettings.Password(), fSettings.UseSSL()); + status_t status; + int tries = 6; + while (tries-- > 0) { + status = fProtocol.Connect(fSettings.ServerAddress(), + fSettings.Username(), fSettings.Password(), fSettings.UseSSL()); + if (status == B_OK) + break; + + // Wait for 10 seconds, and try again + snooze(10000000); + } + // TODO: if other workers are connected, but it fails for us, we need to + // remove this worker, and reduce the number of concurrent connections if (status != B_OK) return status;