libev migration - add shutdown handlers
authorWilfried Goesgens <dothebart@citadel.org>
Mon, 31 Jan 2011 00:35:40 +0000 (01:35 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Mon, 31 Jan 2011 00:35:40 +0000 (01:35 +0100)
  - this ties us to libev > 4.0
  - clean shutdown and storing of the new state in our quue

citadel/debian/control
citadel/event_client.c
citadel/event_client.h
citadel/modules/smtp/serv_smtpeventclient.c

index 6b6135367a01a07b7173920131341384450d38d2..d1cfe12f2d93482c063fe09a1afc1c08a533ed4a 100644 (file)
@@ -5,7 +5,7 @@ Maintainer: Wilfried Goesgens <w.goesgens@outgesourced.org>
 Build-Depends: debhelper (>= 4), po-debconf, bison, autotools-dev,
  libdb-dev, libical-dev (>=0.43), libldap2-dev, gettext, locales,
  libpam0g-dev, libsieve2-dev, libssl-dev, libexpat1-dev, libcitadel-dev (>= 7.42),
- libcurl4-openssl-dev | libcurl3-openssl-dev, zlib1g-dev, libev-dev, libc-ares-dev (>= 1.7.2)
+ libcurl4-openssl-dev | libcurl3-openssl-dev, zlib1g-dev, libev-dev (>= 4.0), libc-ares-dev (>= 1.7.2)
 Standards-Version: 3.8.0
 
 Package: citadel-server
index 960ca4d55ab2610556236afc06d8afe71aa06330..5c16cdd5bf78baaee63b0a931867e3be10fe5e57 100644 (file)
@@ -73,6 +73,14 @@ extern struct ev_loop *event_base;
 extern ev_async AddJob;   
 extern ev_async ExitEventLoop;
 
+static void
+IO_abort_shutdown_callback(struct ev_loop *loop, ev_cleanup *watcher, int revents)
+{
+       CtdlLogPrintf(CTDL_DEBUG, "EVENT Q: %s\n", __FUNCTION__);
+
+       AsyncIO *IO = watcher->data;
+       IO->ShutdownAbort(IO);
+}
        
 int QueueEventContext(AsyncIO *IO, IO_CallBack CB)
 {
@@ -82,6 +90,10 @@ int QueueEventContext(AsyncIO *IO, IO_CallBack CB)
        h = (IOAddHandler*)malloc(sizeof(IOAddHandler));
        h->IO = IO;
        h->EvAttch = CB;
+       ev_cleanup_init(&IO->abort_by_shutdown, 
+                       IO_abort_shutdown_callback);
+       IO->abort_by_shutdown.data = IO;
+       ev_cleanup_start(event_base, &IO->abort_by_shutdown);
 
        citthread_mutex_lock(&EventQueueMutex);
        CtdlLogPrintf(CTDL_DEBUG, "EVENT Q\n");
index 79eda639b7726060b997d3ec43eaf23c661711c8..daf158dcbd22ea7e8bcf72ae1ede86805e866ab0 100644 (file)
@@ -36,6 +36,8 @@ struct AsyncIO {
        int sock;
        unsigned short dport;
                eNextState NextState;
+       
+       ev_cleanup abort_by_shutdown;
 
        ev_timer conn_fail, 
                rw_timeout,
@@ -55,7 +57,8 @@ struct AsyncIO {
                SendDone,     /* we may send more data */
                Terminate,    /* shutting down... */
                Timeout,      /* Timeout handler; may also be connection timeout */
-               ConnFail;     /* What to do when one connection failed? */
+               ConnFail,     /* What to do when one connection failed? */
+               ShutdownAbort;/* we're going down. make your piece. */ 
 
        IO_LineReaderCallback LineReader; /* if we have linereaders, maybe we want to read more lines before the real application logic is called? */
 
index 133ee8fbeba6b6787858b5dfa3080841b6236015..3c4e6d0c8e96df41e71f2224570e81a9fc50207a 100644 (file)
@@ -183,6 +183,7 @@ void DeleteSmtpOutMsg(void *v)
        free(Msg);
 }
 
+eNextState SMTP_C_Shutdown(AsyncIO *IO);
 eNextState SMTP_C_Timeout(AsyncIO *IO);
 eNextState SMTP_C_ConnFail(AsyncIO *IO);
 eNextState SMTP_C_DispatchReadDone(AsyncIO *IO);
@@ -555,17 +556,19 @@ void smtp_try(OneQueItem *MyQItem,
        SendMsg->MyQItem      = MyQItem;
        SendMsg->pCurrRelay   = MyQItem->URL;
 
-       SendMsg->IO.dport       = DefaultMXPort;
-       SendMsg->IO.Data        = SendMsg;
-       SendMsg->IO.SendDone    = SMTP_C_DispatchWriteDone;
-       SendMsg->IO.ReadDone    = SMTP_C_DispatchReadDone;
-       SendMsg->IO.Terminate   = SMTP_C_Terminate;
-       SendMsg->IO.LineReader  = SMTP_C_ReadServerStatus;
-       SendMsg->IO.ConnFail    = SMTP_C_ConnFail;
-       SendMsg->IO.Timeout     = SMTP_C_Timeout;
-       SendMsg->IO.SendBuf.Buf = NewStrBufPlain(NULL, 1024);
-       SendMsg->IO.RecvBuf.Buf = NewStrBufPlain(NULL, 1024);
-       SendMsg->IO.IOBuf       = NewStrBuf();
+       SendMsg->IO.dport         = DefaultMXPort;
+       SendMsg->IO.Data          = SendMsg;
+       SendMsg->IO.SendDone      = SMTP_C_DispatchWriteDone;
+       SendMsg->IO.ReadDone      = SMTP_C_DispatchReadDone;
+       SendMsg->IO.Terminate     = SMTP_C_Terminate;
+       SendMsg->IO.LineReader    = SMTP_C_ReadServerStatus;
+       SendMsg->IO.ConnFail      = SMTP_C_ConnFail;
+       SendMsg->IO.Timeout       = SMTP_C_Timeout;
+       SendMsg->IO.ShutdownAbort = SMTP_C_Shutdown;
+       SendMsg->IO.SendBuf.Buf   = NewStrBufPlain(NULL, 1024);
+       SendMsg->IO.RecvBuf.Buf   = NewStrBufPlain(NULL, 1024);
+       SendMsg->IO.IOBuf         = NewStrBuf();
+                       
 
        if (KeepMsgText) {
                SendMsg->msgtext    = MsgText;
@@ -966,6 +969,16 @@ eNextState SMTP_C_ConnFail(AsyncIO *IO)
        FinalizeMessageSend(pMsg);
        return eAbort;
 }
+eNextState SMTP_C_Shutdown(AsyncIO *IO)
+{
+       CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
+       SmtpOutMsg *pMsg = IO->Data;
+
+       pMsg->MyQEntry->Status = 3;
+       StrBufPlain(pMsg->MyQEntry->StatusMessage, HKEY("server shutdown during message submit."));
+       FinalizeMessageSend(pMsg);
+       return eAbort;
+}
 
 
 /**