libev migration - add shutdown handlers
[citadel.git] / citadel / modules / smtp / serv_smtpeventclient.c
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;
+}
 
 
 /**