EVENT Client: parametrize when to close the fd on detach or not
authorWilfried Goesgens <dothebart@citadel.org>
Tue, 19 Jun 2012 21:50:21 +0000 (23:50 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Tue, 19 Jun 2012 21:50:21 +0000 (23:50 +0200)
  - 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
citadel/event_client.h
citadel/modules/pop3client/serv_pop3client.c
citadel/modules/smtp/serv_smtpeventclient.c

index bd0b8a105be45f9cda7a142a32860a8331b36052..383668c45722027327f21b26ccebddf44e8cbb55 100644 (file)
@@ -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);
index 7a936b97bf463982ac0f103c7c5b10e5d04bdd27..320beb746cb3a6e7d72e53e6a399050261030ef2 100644 (file)
@@ -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);
 
index 44ddd7772599a0bb81122bff1fcb7d634fd082a3..599a35e69f396fd994c6621a78cd50f283d0d705 100644 (file)
@@ -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);
 }
 
index c7de74fac3e9da7fffd65b10251b42c36a9411af..56deb4f5034f1785952ea0e6cf6ca4b6830bfdb9 100644 (file)
@@ -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;