[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    Re: KMail pop downloads
From:       Julian Rockey <linux () jrockey ! com>
Date:       2004-06-27 21:47:13
Message-ID: 200406272247.13846.linux () jrockey ! com
[Download RAW message or body]

I've had a go at this. Please could someone take a look at the attached and 
comment. I can commit it if a KMail developer gives me the OK.

In it's present form it's not configurable via a GUI. Should this be added 
perhaps to the Misc config form, or left as a config-file-edit-only options 
for "advanced" users?

cheers
Julian

On Thursday 24 June 2004 00:48, Ingo Klöcker wrote:
> IIUC then this only happens because all POP accounts are on the same
> server. Therefore I'd prefer a solution which ensure that a maximum of
> {configurable X} POP jobs per server are running at a time.
>
> It's correct that you'll have to alter KMAcctMgr::processNextCheck(). In
> the following loop you have to skip accounts which would create the
> X+1st job for a certain server. You should use a QMap<QString,int> to
> count the number of running jobs per server.
>
>   for ( ; it != last; it++ )
>   {
>     if ( !(*it)->checkingMail() ) {
>       curAccount = (*it);
>       mAcctTodo.remove( curAccount );
>       break;
>     }
>   }
>
> Regards,
> Ingo

["kmail-20040627.diff" (text/x-diff)]

Index: kmacctmgr.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmacctmgr.cpp,v
retrieving revision 1.116
diff -u -3 -p -r1.116 kmacctmgr.cpp
--- kmacctmgr.cpp	7 Jun 2004 21:57:23 -0000	1.116
+++ kmacctmgr.cpp	27 Jun 2004 21:32:02 -0000
@@ -32,6 +32,7 @@ KMAcctMgr::KMAcctMgr(): QObject()
   mAcctChecking.clear();
   mAcctTodo.clear();
   mTotalNewMailsArrived=0;
+  mMaxConnectionsPerHost=-1;
   mDisplaySummary = false;
 }
 
@@ -51,6 +52,7 @@ void KMAcctMgr::writeConfig(bool withSyn
 
   KConfigGroupSaver saver(config, "General");
   config->writeEntry("accounts", mAcctList.count());
+  config->writeEntry("max-connections-per-host", mMaxConnectionsPerHost);
 
   // first delete all account groups in the config file:
   QStringList accountGroups =
@@ -85,6 +87,8 @@ void KMAcctMgr::readConfig(void)
 
   KConfigGroup general(config, "General");
   num = general.readNumEntry("accounts", 0);
+  mMaxConnectionsPerHost = general.readNumEntry("max-connections-per-host", -1);
+  kdDebug(5006) << "read max-connections-per-host as " << mMaxConnectionsPerHost << \
endl;  
   for (i=1; i<=num; i++)
   {
@@ -141,6 +145,13 @@ void KMAcctMgr::processNextCheck(bool _n
       kmkernel->filterMgr()->deref();
       disconnect( acct, SIGNAL( finishedCheck( bool, CheckStatus ) ),
                   this, SLOT( processNextCheck( bool ) ) );
+      QString hostname = hostForAccount(acct);
+      if (!hostname.isNull()) {
+        if (mServerConnections.find(hostname)!=mServerConnections.end()) {
+          mServerConnections[hostname] -= 1;
+          kdDebug(5006) << "connections to server " << hostname << " now " << \
mServerConnections[hostname] << endl; +        }
+      }
     }
   }
   if (mAcctChecking.isEmpty())
@@ -156,12 +167,21 @@ void KMAcctMgr::processNextCheck(bool _n
   }
   if (mAcctTodo.isEmpty()) return;
 
+  QString accountHostName;
+
   curAccount = 0;
   KMAcctList::Iterator it ( mAcctTodo.begin() );
   KMAcctList::Iterator last ( mAcctTodo.end() );
   for ( ; it != last; it++ )
   {
-    if ( !(*it)->checkingMail() ) {
+    accountHostName = hostForAccount(*it);
+    kdDebug(5006) << "for host " << accountHostName << " current connections=" << \
(mServerConnections.find(accountHostName)==mServerConnections.end() ? 0 : \
mServerConnections[accountHostName]) << " and limit is " << mMaxConnectionsPerHost << \
endl; +    bool connectionLimitForHostReached =
+      !accountHostName.isNull() && mMaxConnectionsPerHost>0 &&
+      mServerConnections.find(accountHostName) != mServerConnections.end() &&
+      mServerConnections[accountHostName] >= mMaxConnectionsPerHost;
+    kdDebug(5006) << "connection limit reached: " << connectionLimitForHostReached \
<< endl; +    if ( !(*it)->checkingMail() && !connectionLimitForHostReached) {
       curAccount = (*it);
       mAcctTodo.remove( curAccount );
       break;
@@ -195,6 +215,14 @@ void KMAcctMgr::processNextCheck(bool _n
   mAcctChecking.append(curAccount);
   kmkernel->filterMgr()->ref();
   curAccount->processNewMail(interactive);
+
+  if (!accountHostName.isNull()) {
+    if (mServerConnections.find(accountHostName)!=mServerConnections.end())
+      mServerConnections[accountHostName] += 1;
+    else
+      mServerConnections[accountHostName] = 1;
+    kdDebug(5006) << "check mail started - connections for host " << accountHostName \
<< " now is " << mServerConnections[accountHostName] << endl; +  }
 }
 
 //-----------------------------------------------------------------------------
@@ -413,4 +441,10 @@ void KMAcctMgr::cancelMailCheck()
   }
 }
 
+QString KMAcctMgr::hostForAccount(const KMAccount *acct) const
+{
+  const NetworkAccount *net_acct = dynamic_cast<const NetworkAccount*>(acct);
+  return net_acct==NULL ? QString::null : net_acct->host();
+}
+
 #include "kmacctmgr.moc"
Index: kmacctmgr.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmacctmgr.h,v
retrieving revision 1.44
diff -u -3 -p -r1.44 kmacctmgr.h
--- kmacctmgr.h	7 Jun 2004 21:57:23 -0000	1.44
+++ kmacctmgr.h	27 Jun 2004 21:32:02 -0000
@@ -99,12 +99,18 @@ private:
   bool newMailArrived;
   bool interactive;
   int  mTotalNewMailsArrived;
+  int  mMaxConnectionsPerHost;
 
   // for detailed (per folder) new mail notification
   QMap<QString, int> mTotalNewInFolder;
 
+  // for restricting number of concurrent connections to the same server
+  QMap<QString, int> mServerConnections;
+  QString hostForAccount(const KMAccount *acct) const;
+
   // if a summary should be displayed
   bool mDisplaySummary;
+
 };
 
 #endif /*kmacctmgr_h*/



_______________________________________________
KMail developers mailing list
KMail-devel@kde.org
https://mail.kde.org/mailman/listinfo/kmail-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic