From: Wilfried Goesgens Date: Mon, 31 Jan 2011 00:35:40 +0000 (+0100) Subject: libev migration - add shutdown handlers X-Git-Tag: v8.11~1092 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=92abe2ec552ee13a56e744dfb34fad5b7d785a24 libev migration - add shutdown handlers - this ties us to libev > 4.0 - clean shutdown and storing of the new state in our quue --- diff --git a/citadel/debian/control b/citadel/debian/control index 6b6135367..d1cfe12f2 100644 --- a/citadel/debian/control +++ b/citadel/debian/control @@ -5,7 +5,7 @@ Maintainer: Wilfried Goesgens 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 diff --git a/citadel/event_client.c b/citadel/event_client.c index 960ca4d55..5c16cdd5b 100644 --- a/citadel/event_client.c +++ b/citadel/event_client.c @@ -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"); diff --git a/citadel/event_client.h b/citadel/event_client.h index 79eda639b..daf158dcb 100644 --- a/citadel/event_client.h +++ b/citadel/event_client.h @@ -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? */ diff --git a/citadel/modules/smtp/serv_smtpeventclient.c b/citadel/modules/smtp/serv_smtpeventclient.c index 133ee8fbe..3c4e6d0c8 100644 --- a/citadel/modules/smtp/serv_smtpeventclient.c +++ b/citadel/modules/smtp/serv_smtpeventclient.c @@ -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; +} /**