From 67a31b2b42fdbabd942ddf051c63c85809a7180b Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sat, 2 Apr 2011 17:24:17 +0200 Subject: [PATCH] Cleanup the event client struct, remove unused vars --- citadel/event_client.c | 30 +++++++++--------- citadel/event_client.h | 35 +++++++++------------ citadel/modules/smtp/serv_smtpeventclient.c | 5 ++- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/citadel/event_client.c b/citadel/event_client.c index fcd985048..2902b3d91 100644 --- a/citadel/event_client.c +++ b/citadel/event_client.c @@ -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); diff --git a/citadel/event_client.h b/citadel/event_client.h index a8534b148..33a4d0b90 100644 --- a/citadel/event_client.h +++ b/citadel/event_client.h @@ -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 { diff --git a/citadel/modules/smtp/serv_smtpeventclient.c b/citadel/modules/smtp/serv_smtpeventclient.c index 3276f90f0..15a55e799 100644 --- a/citadel/modules/smtp/serv_smtpeventclient.c +++ b/citadel/modules/smtp/serv_smtpeventclient.c @@ -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); -- 2.30.2