Cleanup the event client struct, remove unused vars
authorWilfried Goesgens <dothebart@citadel.org>
Sat, 2 Apr 2011 15:24:17 +0000 (17:24 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Sat, 2 Apr 2011 15:24:17 +0000 (17:24 +0200)
citadel/event_client.c
citadel/event_client.h
citadel/modules/smtp/serv_smtpeventclient.c

index fcd985048094b468796f0d7658c02163f0e11c90..2902b3d913cc66c6bdbefe5472d28cf24f093110 100644 (file)
@@ -125,17 +125,16 @@ void FreeAsyncIOContents(AsyncIO *IO)
 
 void ShutDownCLient(AsyncIO *IO)
 {
-       CtdlLogPrintf(CTDL_DEBUG, "EVENT x %d\n", IO->sock);
+       CtdlLogPrintf(CTDL_DEBUG, "EVENT x %d\n", IO->SendBuf.fd);
 
        ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
 
-       if (IO->sock != 0)
+       if (IO->SendBuf.fd != 0)
        {
                ev_io_stop(event_base, &IO->send_event);
                ev_io_stop(event_base, &IO->recv_event);
                ev_timer_stop (event_base, &IO->rw_timeout);
-               close(IO->sock);
-               IO->sock = 0;
+               close(IO->SendBuf.fd);
                IO->SendBuf.fd = 0;
                IO->RecvBuf.fd = 0;
        }
@@ -226,7 +225,7 @@ IO_send_callback(struct ev_loop *loop, ev_io *watcher, int revents)
                                pchh = pch;
                        
                        nbytes = StrLength(IO->SendBuf.Buf) - (pchh - pch);
-                       snprintf(fn, SIZ, "/tmp/foolog_ev_%s.%d", "smtpev", IO->sock);
+                       snprintf(fn, SIZ, "/tmp/foolog_ev_%s.%d", "smtpev", IO->SendBuf.fd);
                
                        fd = fopen(fn, "a+");
                        fprintf(fd, "Read: BufSize: %ld BufContent: [",
@@ -354,18 +353,18 @@ eNextState event_connect_socket(AsyncIO *IO, double conn_timeout, double first_r
        int rc = -1;
 
        IO->SendBuf.fd = IO->RecvBuf.fd = 
-               IO->sock = socket(
+               socket(
                        (IO->ConnectMe->IPv6)?PF_INET6:PF_INET, 
                        SOCK_STREAM, 
                        IPPROTO_TCP);
 
-       if (IO->sock < 0) {
+       if (IO->SendBuf.fd < 0) {
                CtdlLogPrintf(CTDL_ERR, "EVENT: socket() failed: %s\n", strerror(errno));
                StrBufPrintf(IO->ErrMsg, "Failed to create socket: %s", strerror(errno));
 //             freeaddrinfo(res);
                return eAbort;
        }
-       fdflags = fcntl(IO->sock, F_GETFL);
+       fdflags = fcntl(IO->SendBuf.fd, F_GETFL);
        if (fdflags < 0) {
                CtdlLogPrintf(CTDL_DEBUG,
                              "EVENT: unable to get socket flags! %s \n",
@@ -374,20 +373,21 @@ eNextState event_connect_socket(AsyncIO *IO, double conn_timeout, double first_r
                return eAbort;
        }
        fdflags = fdflags | O_NONBLOCK;
-       if (fcntl(IO->sock, F_SETFL, fdflags) < 0) {
+       if (fcntl(IO->SendBuf.fd, F_SETFL, fdflags) < 0) {
                CtdlLogPrintf(CTDL_DEBUG,
                              "EVENT: unable to set socket nonblocking flags! %s \n",
                              strerror(errno));
                StrBufPrintf(IO->ErrMsg, "Failed to set socket flags: %s", strerror(errno));
-               close(IO->sock);
+               close(IO->SendBuf.fd);
+               IO->SendBuf.fd = IO->RecvBuf.fd = -1;
                return eAbort;
        }
 /* TODO: maye we could use offsetof() to calc the position of data... 
  * http://doc.dvgu.ru/devel/ev.html#associating_custom_data_with_a_watcher
  */
-       ev_io_init(&IO->recv_event, IO_recv_callback, IO->sock, EV_READ);
+       ev_io_init(&IO->recv_event, IO_recv_callback, IO->RecvBuf.fd, EV_READ);
        IO->recv_event.data = IO;
-       ev_io_init(&IO->send_event, IO_send_callback, IO->sock, EV_WRITE);
+       ev_io_init(&IO->send_event, IO_send_callback, IO->SendBuf.fd, EV_WRITE);
        IO->send_event.data = IO;
 
        ev_timer_init(&IO->conn_fail, IO_connfail_callback, conn_timeout, 0);
@@ -396,9 +396,9 @@ eNextState event_connect_socket(AsyncIO *IO, double conn_timeout, double first_r
        IO->rw_timeout.data = IO;
 
        if (IO->ConnectMe->IPv6)
-               rc = connect(IO->sock, &IO->ConnectMe->Addr, sizeof(struct sockaddr_in6));
+               rc = connect(IO->SendBuf.fd, &IO->ConnectMe->Addr, sizeof(struct sockaddr_in6));
        else
-               rc = connect(IO->sock, (struct sockaddr_in *)&IO->ConnectMe->Addr, sizeof(struct sockaddr_in));
+               rc = connect(IO->SendBuf.fd, (struct sockaddr_in *)&IO->ConnectMe->Addr, sizeof(struct sockaddr_in));
 
        if (rc >= 0){
 ////           freeaddrinfo(res);
@@ -408,7 +408,7 @@ eNextState event_connect_socket(AsyncIO *IO, double conn_timeout, double first_r
        }
        else if (errno == EINPROGRESS) {
 
-               ev_io_init(&IO->conn_event, IO_connestd_callback, IO->sock, EV_READ|EV_WRITE);
+               ev_io_init(&IO->conn_event, IO_connestd_callback, IO->SendBuf.fd, EV_READ|EV_WRITE);
                IO->conn_event.data = IO;
 
                ev_io_start(event_base, &IO->conn_event);
index a8534b1486b8df7d6baa981bd1e994ba2169be57..33a4d0b90f8585a1df553899dc9936e81fe28230 100644 (file)
@@ -32,33 +32,27 @@ typedef struct _DNSQueryParts {
 
 
 struct AsyncIO {
+               eNextState NextState;
 
        /* connection related */
        ParsedURL *ConnectMe;
-/*
-       int IP6;
-       struct sockaddr_in6 *Addr;
-       unsigned short dport;
-
-*/
-       int sock;
-               eNextState NextState;
        
-       ev_cleanup abort_by_shutdown;
-
-       ev_timer conn_fail, 
-               rw_timeout;
-       ev_idle unwind_stack;
-       ev_io recv_event, 
-               send_event, 
-               conn_event;
-       StrBuf *ErrMsg; /* if we fail to connect, or lookup, error goes here. */
-
        /* read/send related... */
        StrBuf *IOBuf;
        IOBuffer SendBuf, 
                RecvBuf;
 
+       /* our events... */
+       ev_cleanup abort_by_shutdown; /* server wants to go down... */
+       ev_timer conn_fail,           /* connection establishing timed out */
+               rw_timeout;           /* timeout while sending data */
+       ev_idle unwind_stack;         /* get c-ares out of the stack */
+       ev_io recv_event,             /* receive data from the client */
+               send_event,           /* send more data to the client */
+               conn_event;           /* Connection successfully established */
+
+       StrBuf *ErrMsg; /* if we fail to connect, or lookup, error goes here. */
+
        /* Citadel application callbacks... */
        IO_CallBack ReadDone, /* Theres new data to read... */
                SendDone,     /* we may send more data */
@@ -69,6 +63,7 @@ struct AsyncIO {
 
        IO_LineReaderCallback LineReader; /* if we have linereaders, maybe we want to read more lines before the real application logic is called? */
 
+       /* DNS Related */
        ev_io dns_recv_event, 
                dns_send_event;
        struct ares_options DNSOptions;
@@ -76,8 +71,8 @@ struct AsyncIO {
        DNSQueryParts *DNSQuery;
 
        /* Custom data; its expected to contain  AsyncIO so we can save malloc()s... */
-       DeleteHashDataFunc DeleteData; /* so if we have to destroy you, what to do... */
-       void *Data; /* application specific data */
+       void *Data;        /* application specific data */
+       void *CitContext;  /* Citadel Session context... */
 };
 
 typedef struct _IOAddHandler {
index 3276f90f0036581baeabcc499a9ede6469cf3445..15a55e79960758b4237ccdbf1b209c9dc6fab30b 100644 (file)
@@ -430,7 +430,6 @@ SmtpOutMsg *new_smtp_outmsg(OneQueItem *MyQItem,
        SendMsg->IO.RecvBuf.Buf   = NewStrBufPlain(NULL, 1024);
        SendMsg->IO.IOBuf         = NewStrBuf();
 
-       SendMsg->IO.sock          = (-1);
        SendMsg->IO.NextState     = eReadMessage;
        
        return SendMsg;
@@ -451,6 +450,10 @@ void smtp_try_one_queue_entry(OneQueItem *MyQItem,
        else             SendMsg->msgtext = NewStrBufDup(MsgText);
        
        if (smtp_resolve_recipients(SendMsg)) {
+
+               
+
+
                if (SendMsg->pCurrRelay == NULL)
                        QueueEventContext(&SendMsg->IO,
                                          resolve_mx_records);