EV: stop all watchers before going into other queues - so we can avoid race conditions.
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 26 May 2013 13:46:09 +0000 (15:46 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 26 May 2013 13:46:09 +0000 (15:46 +0200)
citadel/event_client.c
citadel/event_client.h
citadel/modules/pop3client/serv_pop3client.c
citadel/modules/rssclient/serv_rssclient.c
citadel/modules/smtp/serv_smtpeventclient.c

index 68995dd..c9c149f 100644 (file)
@@ -295,6 +295,17 @@ eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB)
        return eSendReply;
 }
 
+eNextState EventQueueDBOperation(AsyncIO *IO, IO_CallBack CB)
+{
+       StopClientWatchers(IO, 0);
+       return QueueDBOperation(IO, CB);
+}
+eNextState DBQueueEventContext(AsyncIO *IO, IO_CallBack CB)
+{
+       StopDBWatchers(IO);
+       return QueueEventContext(IO, CB);
+}
+
 extern eNextState evcurl_handle_start(AsyncIO *IO);
 
 eNextState QueueCurlContext(AsyncIO *IO)
@@ -334,6 +345,13 @@ eNextState QueueCurlContext(AsyncIO *IO)
        return eSendReply;
 }
 
+eNextState CurlQueueDBOperation(AsyncIO *IO, IO_CallBack CB)
+{
+       StopCurlWatchers(IO);
+       return QueueDBOperation(IO, CB);
+}
+
+
 void DestructCAres(AsyncIO *IO);
 void FreeAsyncIOContents(AsyncIO *IO)
 {
index 1dce3d9..b136c2e 100644 (file)
@@ -278,9 +278,11 @@ void FreeAsyncIOContents(AsyncIO *IO);
 
 eNextState NextDBOperation(AsyncIO *IO, IO_CallBack CB);
 eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB);
+eNextState EventQueueDBOperation(AsyncIO *IO, IO_CallBack CB);
 void StopDBWatchers(AsyncIO *IO);
 eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB);
 eNextState QueueCurlContext(AsyncIO *IO);
+eNextState DBQueueEventContext(AsyncIO *IO, IO_CallBack CB);
 
 eNextState EvConnectSock(AsyncIO *IO,
                         double conn_timeout,
@@ -342,6 +344,7 @@ int InitcURLIOStruct(AsyncIO *IO,
 void KillAsyncIOContext(AsyncIO *IO);
 void StopCurlWatchers(AsyncIO *IO);
 
+eNextState CurlQueueDBOperation(AsyncIO *IO, IO_CallBack CB);
 
 eNextState ReAttachIO(AsyncIO *IO,
                      void *pData,
index e23f9b1..8a12d15 100644 (file)
@@ -454,8 +454,7 @@ eNextState POP3_FetchNetworkUsetableEntry(AsyncIO *IO)
                /* ok, now we know them all,
                 * continue with reading the actual messages. */
                DeleteHashPos(&RecvMsg->Pos);
-               StopDBWatchers(IO);
-               return QueueEventContext(IO, POP3_C_ReAttachToFetchMessages);
+               return DBQueueEventContext(IO, POP3_C_ReAttachToFetchMessages);
        }
 }
 
@@ -492,8 +491,8 @@ eNextState POP3C_GetOneMessagID(pop3aggr *RecvMsg)
                DeleteHashPos(&RecvMsg->Pos);
                /// done receiving uidls.. start looking them up now.
                RecvMsg->Pos = GetNewHashPos(RecvMsg->MsgNumbers, 0);
-               return QueueDBOperation(&RecvMsg->IO,
-                                       POP3_FetchNetworkUsetableEntry);
+               return EventQueueDBOperation(&RecvMsg->IO,
+                                            POP3_FetchNetworkUsetableEntry);
        }
        return eReadMore; /* TODO */
 }
@@ -595,8 +594,7 @@ eNextState POP3C_StoreMsgRead(AsyncIO *IO)
                           eWrite,
                           IO->ID, CCID);
 
-       StopDBWatchers(IO);
-       return QueueEventContext(&RecvMsg->IO, POP3_C_ReAttachToFetchMessages);
+       return DBQueueEventContext(&RecvMsg->IO, POP3_C_ReAttachToFetchMessages);
 }
 eNextState POP3C_SaveMsg(AsyncIO *IO)
 {
@@ -627,8 +625,7 @@ eNextState POP3C_ReadMessageBody(pop3aggr *RecvMsg)
        EVP3CM_syslog(LOG_DEBUG, "Converting message...");
        RecvMsg->CurrMsg->Msg =
                convert_internet_message_buf(&RecvMsg->IO.ReadMsg->MsgBuf);
-       StopClientWatchers(IO, 0);
-       return QueueDBOperation(&RecvMsg->IO, POP3C_SaveMsg);
+       return EventQueueDBOperation(&RecvMsg->IO, POP3C_SaveMsg);
 }
 
 eNextState POP3C_SendDelete(pop3aggr *RecvMsg)
index dfed6bc..5f13576 100644 (file)
@@ -592,7 +592,7 @@ eNextState RSSAggregator_AnalyseReply(AsyncIO *IO)
 eNextState RSSAggregator_FinishHttp(AsyncIO *IO)
 {
        StopCurlWatchers(IO);
-       return QueueDBOperation(IO, RSSAggregator_AnalyseReply);
+       return CurlQueueDBOperation(IO, RSSAggregator_AnalyseReply);
 }
 
 /*
index dd4e3e2..afdde7d 100644 (file)
@@ -254,7 +254,7 @@ eNextState Terminate(AsyncIO *IO)
 eNextState FinalizeMessageSend(SmtpOutMsg *Msg)
 {
        /* hand over to DB Queue */
-       return QueueDBOperation(&Msg->IO, FinalizeMessageSend_DB);
+       return EventQueueDBOperation(&Msg->IO, FinalizeMessageSend_DB);
 }
 
 eNextState FailOneAttempt(AsyncIO *IO)