]> code.citadel.org Git - citadel.git/blobdiff - citadel/event_client.c
One more place were we have to check whether this is still our context first.
[citadel.git] / citadel / event_client.c
index e75f114ed340e1558442c10c78e3341b59586f82..c46429337da7f1db65dff1b53db14ea916679d38 100644 (file)
@@ -9,61 +9,23 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  */
-
 #include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <termios.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <pwd.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <syslog.h>
 
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-#include <sys/wait.h>
-#include <ctype.h>
+#include <stdio.h>
 #include <string.h>
-#include <limits.h>
+#include <syslog.h>
+#include <assert.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#include <assert.h>
 #if HAVE_BACKTRACE
 #include <execinfo.h>
 #endif
 
 #include <libcitadel.h>
-#include "citadel.h"
-#include "server.h"
-#include "citserver.h"
-#include "support.h"
-#include "config.h"
-#include "control.h"
-#include "user_ops.h"
-#include "database.h"
-#include "msgbase.h"
-#include "internet_addressing.h"
-#include "genstamp.h"
-#include "domain.h"
-#include "clientsocket.h"
-#include "locate_host.h"
-#include "citadel_dirs.h"
 
-#include "event_client.h"
 #include "ctdl_module.h"
-
+#include "event_client.h"
 
 ConstStr IOStates[] = {
        {HKEY("DB Queue")},
@@ -160,7 +122,7 @@ eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB)
        ev_async_send (event_db, &DBAddJob);
        pthread_mutex_unlock(&DBEventExitQueueMutex);
 
-       EVM_syslog(LOG_DEBUG, "DBEVENT Q Done.\n");
+       EVQM_syslog(LOG_DEBUG, "DBEVENT Q Done.\n");
        return eDBQuery;
 }
 
@@ -295,9 +257,9 @@ eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB)
        return eSendReply;
 }
 
-eNextState EventQueueDBOperation(AsyncIO *IO, IO_CallBack CB)
+eNextState EventQueueDBOperation(AsyncIO *IO, IO_CallBack CB, int CloseFDs)
 {
-       StopClientWatchers(IO, 0);
+       StopClientWatchers(IO, CloseFDs);
        return QueueDBOperation(IO, CB);
 }
 eNextState DBQueueEventContext(AsyncIO *IO, IO_CallBack CB)
@@ -352,7 +314,6 @@ eNextState CurlQueueDBOperation(AsyncIO *IO, IO_CallBack CB)
 }
 
 
-void DestructCAres(AsyncIO *IO);
 void FreeAsyncIOContents(AsyncIO *IO)
 {
        CitContext *Ctx = IO->CitContext;
@@ -361,8 +322,6 @@ void FreeAsyncIOContents(AsyncIO *IO)
        FreeStrBuf(&IO->SendBuf.Buf);
        FreeStrBuf(&IO->RecvBuf.Buf);
 
-       DestructCAres(IO);
-
        FreeURL(&IO->ConnectMe);
        FreeStrBuf(&IO->HttpReq.ReplyData);
 
@@ -374,8 +333,13 @@ void FreeAsyncIOContents(AsyncIO *IO)
 }
 
 
+void DestructCAres(AsyncIO *IO);
 void StopClientWatchers(AsyncIO *IO, int CloseFD)
 {
+       EVM_syslog(LOG_DEBUG, "EVENT StopClientWatchers");
+       
+       DestructCAres(IO);
+
        ev_timer_stop (event_base, &IO->rw_timeout);
        ev_timer_stop(event_base, &IO->conn_fail);
        ev_idle_stop(event_base, &IO->unwind_stack);
@@ -529,10 +493,18 @@ eReadState HandleInbound(AsyncIO *IO)
                }
 
                if (Finished != eMustReadMore) {
+                       eNextState rc;
                        assert(IO->ReadDone);
                        ev_io_stop(event_base, &IO->recv_event);
-                       IO->NextState = IO->ReadDone(IO);
-                       Finished = StrBufCheckBuffer(&IO->RecvBuf);
+                       rc = IO->ReadDone(IO);
+                       if  (rc != eDBQuery) {
+                               IO->NextState = rc;
+                               Finished = StrBufCheckBuffer(&IO->RecvBuf);
+                       }
+                       else {
+                               return rc;
+
+                       }
                }
        }