From b6b7232c3d43b56d6606eecd9ae84a396ba8ff25 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Tue, 19 Jun 2012 23:50:21 +0200 Subject: [PATCH] EVENT Client: parametrize when to close the fd on detach or not - we shouldn't close our FD if we want to continue using it later on after doing i.e. database io. --- citadel/event_client.c | 14 +++++++------- citadel/event_client.h | 2 +- citadel/modules/pop3client/serv_pop3client.c | 2 +- citadel/modules/smtp/serv_smtpeventclient.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/citadel/event_client.c b/citadel/event_client.c index bd0b8a105..383668c45 100644 --- a/citadel/event_client.c +++ b/citadel/event_client.c @@ -309,7 +309,7 @@ void FreeAsyncIOContents(AsyncIO *IO) } -void StopClientWatchers(AsyncIO *IO) +void StopClientWatchers(AsyncIO *IO, int CloseFD) { ev_timer_stop (event_base, &IO->rw_timeout); ev_timer_stop(event_base, &IO->conn_fail); @@ -320,11 +320,11 @@ void StopClientWatchers(AsyncIO *IO) ev_io_stop(event_base, &IO->send_event); ev_io_stop(event_base, &IO->recv_event); - if (IO->SendBuf.fd != 0) { + if (CloseFD && (IO->SendBuf.fd > 0)) { close(IO->SendBuf.fd); + IO->SendBuf.fd = -1; + IO->RecvBuf.fd = -1; } - IO->SendBuf.fd = 0; - IO->RecvBuf.fd = 0; } void StopCurlWatchers(AsyncIO *IO) @@ -352,7 +352,7 @@ void ShutDownCLient(AsyncIO *IO) EVM_syslog(LOG_DEBUG, "EVENT Terminating \n"); - StopClientWatchers(IO); + StopClientWatchers(IO, 1); if (IO->DNS.Channel != NULL) { ares_destroy(IO->DNS.Channel); @@ -585,7 +585,7 @@ IO_send_callback(struct ev_loop *loop, ev_io *watcher, int revents) } else if (rc < 0) { if (errno != EAGAIN) { - StopClientWatchers(IO); + StopClientWatchers(IO, 1); EV_syslog(LOG_DEBUG, "EVENT: Socket Invalid! [%d] [%s] [%d]\n", errno, strerror(errno), IO->SendBuf.fd); @@ -817,7 +817,7 @@ IO_recv_callback(struct ev_loop *loop, ev_io *watcher, int revents) } else if (nbytes == -1) { if (errno != EAGAIN) { // FD is gone. kick it. - StopClientWatchers(IO); + StopClientWatchers(IO, 1); EV_syslog(LOG_DEBUG, "EVENT: Socket Invalid! [%d] [%s] [%d]\n", errno, strerror(errno), IO->SendBuf.fd); diff --git a/citadel/event_client.h b/citadel/event_client.h index 7a936b97b..320beb746 100644 --- a/citadel/event_client.h +++ b/citadel/event_client.h @@ -266,7 +266,7 @@ void QueryCbDone(AsyncIO *IO); void StopClient(AsyncIO *IO); -void StopClientWatchers(AsyncIO *IO); +void StopClientWatchers(AsyncIO *IO, int CloseFD); void SetNextTimeout(AsyncIO *IO, double timeout); diff --git a/citadel/modules/pop3client/serv_pop3client.c b/citadel/modules/pop3client/serv_pop3client.c index 44ddd7772..599a35e69 100644 --- a/citadel/modules/pop3client/serv_pop3client.c +++ b/citadel/modules/pop3client/serv_pop3client.c @@ -575,7 +575,7 @@ eNextState POP3C_ReadMessageBody(pop3aggr *RecvMsg) EVP3CM_syslog(LOG_DEBUG, "Converting message..."); RecvMsg->CurrMsg->Msg = convert_internet_message_buf(&RecvMsg->IO.ReadMsg->MsgBuf); - StopClientWatchers(IO); + StopClientWatchers(IO, 0); return QueueDBOperation(&RecvMsg->IO, POP3C_SaveMsg); } diff --git a/citadel/modules/smtp/serv_smtpeventclient.c b/citadel/modules/smtp/serv_smtpeventclient.c index c7de74fac..56deb4f50 100644 --- a/citadel/modules/smtp/serv_smtpeventclient.c +++ b/citadel/modules/smtp/serv_smtpeventclient.c @@ -233,7 +233,7 @@ eNextState FailOneAttempt(AsyncIO *IO) * - connection timeout * - dns lookup failed */ - StopClientWatchers(IO); + StopClientWatchers(IO, 1); if (Msg->pCurrRelay != NULL) Msg->pCurrRelay = Msg->pCurrRelay->Next; -- 2.30.2