aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/async
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-06-22 22:28:41 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-06-22 22:29:05 -0700
commit9682845dd6a6985f396a93ff95adc1dcdeae8861 (patch)
tree67e053e5e87b5c228191440116c1b839dbf2aecc /src/async
parent74752eb7c987a2c1704f6f92486e4a4d3f77cbfb (diff)
Retain session when IMAP and SMTP operations are running. Fixed #127, fixed #128.
Diffstat (limited to 'src/async')
-rw-r--r--src/async/imap/MCIMAPAsyncConnection.cc33
-rw-r--r--src/async/imap/MCIMAPAsyncConnection.h9
-rw-r--r--src/async/imap/MCIMAPAsyncSession.cc1
-rw-r--r--src/async/smtp/MCSMTPAsyncSession.cc8
-rw-r--r--src/async/smtp/MCSMTPSendWithDataOperation.cc2
5 files changed, 48 insertions, 5 deletions
diff --git a/src/async/imap/MCIMAPAsyncConnection.cc b/src/async/imap/MCIMAPAsyncConnection.cc
index 02320b3a..ed40932c 100644
--- a/src/async/imap/MCIMAPAsyncConnection.cc
+++ b/src/async/imap/MCIMAPAsyncConnection.cc
@@ -32,6 +32,7 @@
#include "MCIMAPCapabilityOperation.h"
#include "MCOperationQueueCallback.h"
#include "MCIMAPDisconnectOperation.h"
+#include "MCIMAPAsyncSession.h"
using namespace mailcore;
@@ -45,8 +46,13 @@ namespace mailcore {
virtual ~IMAPOperationQueueCallback() {
}
- virtual void queueIdle() {
+ virtual void queueStartRunning() {
+ mConnection->queueStartRunning();
+ }
+
+ virtual void queueStoppedRunning() {
mConnection->tryAutomaticDisconnect();
+ mConnection->queueStoppedRunning();
}
private:
@@ -63,10 +69,12 @@ IMAPAsyncConnection::IMAPAsyncConnection()
mLastFolder = NULL;
mQueueCallback = new IMAPOperationQueueCallback(this);
mQueue->setCallback(mQueueCallback);
+ mOwner = NULL;
}
IMAPAsyncConnection::~IMAPAsyncConnection()
{
+ cancelDelayedPerformMethod((Object::Method) &IMAPAsyncConnection::tryAutomaticDisconnectAfterDelay, NULL);
MC_SAFE_RELEASE(mQueueCallback);
MC_SAFE_RELEASE(mLastFolder);
MC_SAFE_RELEASE(mDefaultNamespace);
@@ -485,6 +493,18 @@ void IMAPAsyncConnection::tryAutomaticDisconnectAfterDelay(void * context)
op->start();
}
+void IMAPAsyncConnection::queueStartRunning()
+{
+ this->retain();
+ mOwner->retain();
+}
+
+void IMAPAsyncConnection::queueStoppedRunning()
+{
+ mOwner->release();
+ this->release();
+}
+
void IMAPAsyncConnection::setLastFolder(String * folder)
{
MC_SAFE_REPLACE_COPY(String, mLastFolder, folder);
@@ -495,3 +515,14 @@ String * IMAPAsyncConnection::lastFolder()
return mLastFolder;
}
+void IMAPAsyncConnection::setOwner(IMAPAsyncSession * owner)
+{
+ mOwner = owner;
+}
+
+IMAPAsyncSession * IMAPAsyncConnection::owner()
+{
+ return mOwner;
+}
+
+
diff --git a/src/async/imap/MCIMAPAsyncConnection.h b/src/async/imap/MCIMAPAsyncConnection.h
index 7869644c..d6ef6a91 100644
--- a/src/async/imap/MCIMAPAsyncConnection.h
+++ b/src/async/imap/MCIMAPAsyncConnection.h
@@ -26,6 +26,7 @@ namespace mailcore {
class IMAPIdentityOperation;
class IMAPCapabilityOperation;
class IMAPOperationQueueCallback;
+ class IMAPAsyncSession;
class IMAPAsyncConnection : public Object {
public:
@@ -118,7 +119,8 @@ namespace mailcore {
IMAPNamespace * mDefaultNamespace;
String * mLastFolder;
IMAPOperationQueueCallback * mQueueCallback;
-
+ IMAPAsyncSession * mOwner;
+
virtual void tryAutomaticDisconnectAfterDelay(void * context);
public: // private
@@ -131,6 +133,11 @@ namespace mailcore {
virtual String * lastFolder();
virtual void tryAutomaticDisconnect();
+ virtual void queueStartRunning();
+ virtual void queueStoppedRunning();
+
+ virtual void setOwner(IMAPAsyncSession * owner);
+ virtual IMAPAsyncSession * owner();
};
}
diff --git a/src/async/imap/MCIMAPAsyncSession.cc b/src/async/imap/MCIMAPAsyncSession.cc
index 3fbd5470..7c085e4a 100644
--- a/src/async/imap/MCIMAPAsyncSession.cc
+++ b/src/async/imap/MCIMAPAsyncSession.cc
@@ -174,6 +174,7 @@ unsigned int IMAPAsyncSession::maximumConnections()
IMAPAsyncConnection * IMAPAsyncSession::session()
{
IMAPAsyncConnection * session = new IMAPAsyncConnection();
+ session->setOwner(this);
session->autorelease();
session->setHostname(mHostname);
diff --git a/src/async/smtp/MCSMTPAsyncSession.cc b/src/async/smtp/MCSMTPAsyncSession.cc
index cf028ced..73bc2a54 100644
--- a/src/async/smtp/MCSMTPAsyncSession.cc
+++ b/src/async/smtp/MCSMTPAsyncSession.cc
@@ -19,8 +19,13 @@ namespace mailcore {
virtual ~SMTPOperationQueueCallback() {
}
- virtual void queueIdle() {
+ virtual void queueStartRunning() {
+ mSession->retain();
+ }
+
+ virtual void queueStoppedRunning() {
mSession->tryAutomaticDisconnect();
+ mSession->release();
}
private:
@@ -38,6 +43,7 @@ SMTPAsyncSession::SMTPAsyncSession()
SMTPAsyncSession::~SMTPAsyncSession()
{
+ cancelDelayedPerformMethod((Object::Method) &SMTPAsyncSession::tryAutomaticDisconnectAfterDelay, NULL);
MC_SAFE_RELEASE(mQueueCallback);
MC_SAFE_RELEASE(mQueue);
MC_SAFE_RELEASE(mSession);
diff --git a/src/async/smtp/MCSMTPSendWithDataOperation.cc b/src/async/smtp/MCSMTPSendWithDataOperation.cc
index b64f835b..bb2c5ea9 100644
--- a/src/async/smtp/MCSMTPSendWithDataOperation.cc
+++ b/src/async/smtp/MCSMTPSendWithDataOperation.cc
@@ -38,6 +38,4 @@ void SMTPSendWithDataOperation::main()
ErrorCode error;
session()->session()->sendMessage(mMessageData, this, &error);
setError(error);
-
- //tryAutomaticDisconnect();
}