Instead of initiating the transition between DB & IO-Queue from within the applicatio...
authorWilfried Goesgens <dothebart@citadel.org>
Thu, 6 Nov 2014 23:38:18 +0000 (00:38 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Thu, 6 Nov 2014 23:38:18 +0000 (00:38 +0100)
citadel/event_client.c
citadel/event_client.h
citadel/modules/eventclient/serv_eventclient.c

index c46429337da7f1db65dff1b53db14ea916679d38..bdb33dd735f347dae83c400643d06c30be674fec 100644 (file)
@@ -86,7 +86,7 @@ extern struct ev_loop *event_db;
 extern ev_async DBAddJob;
 extern ev_async DBExitEventLoop;
 
-eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB)
+eNextState QueueAnDBOperation(AsyncIO *IO)
 {
        IOAddHandler *h;
        int i;
@@ -94,7 +94,10 @@ eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB)
        SetEVState(IO, eDBQ);
        h = (IOAddHandler*)malloc(sizeof(IOAddHandler));
        h->IO = IO;
-       h->EvAttch = CB;
+
+       assert(IO->ReAttachCB != NULL);
+
+       h->EvAttch = IO->ReAttachCB;
        ev_cleanup_init(&IO->db_abort_by_shutdown,
                        IO_abort_shutdown_callback);
        IO->db_abort_by_shutdown.data = IO;
@@ -219,7 +222,7 @@ static void IO_abort_shutdown_callback(struct ev_loop *loop,
 }
 
 
-eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB)
+eNextState QueueAnEventContext(AsyncIO *IO)
 {
        IOAddHandler *h;
        int i;
@@ -227,7 +230,11 @@ eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB)
        SetEVState(IO, eIOQ);
        h = (IOAddHandler*)malloc(sizeof(IOAddHandler));
        h->IO = IO;
-       h->EvAttch = CB;
+
+       assert(IO->ReAttachCB != NULL);
+
+       h->EvAttch = IO->ReAttachCB;
+
        ev_cleanup_init(&IO->abort_by_shutdown,
                        IO_abort_shutdown_callback);
        IO->abort_by_shutdown.data = IO;
@@ -260,12 +267,20 @@ eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB)
 eNextState EventQueueDBOperation(AsyncIO *IO, IO_CallBack CB, int CloseFDs)
 {
        StopClientWatchers(IO, CloseFDs);
-       return QueueDBOperation(IO, CB);
+       IO->ReAttachCB = CB;
+       return eDBQuery;
 }
 eNextState DBQueueEventContext(AsyncIO *IO, IO_CallBack CB)
 {
        StopDBWatchers(IO);
-       return QueueEventContext(IO, CB);
+       IO->ReAttachCB = CB;
+       return eSendReply;
+}
+
+eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB)
+{
+       IO->ReAttachCB = CB;
+       return QueueAnEventContext(IO);
 }
 
 extern eNextState evcurl_handle_start(AsyncIO *IO);
@@ -310,7 +325,8 @@ eNextState QueueCurlContext(AsyncIO *IO)
 eNextState CurlQueueDBOperation(AsyncIO *IO, IO_CallBack CB)
 {
        StopCurlWatchers(IO);
-       return QueueDBOperation(IO, CB);
+       IO->ReAttachCB = CB;
+       return eDBQuery;
 }
 
 
@@ -497,13 +513,12 @@ eReadState HandleInbound(AsyncIO *IO)
                        assert(IO->ReadDone);
                        ev_io_stop(event_base, &IO->recv_event);
                        rc = IO->ReadDone(IO);
-                       if  (rc != eDBQuery) {
-                               IO->NextState = rc;
-                               Finished = StrBufCheckBuffer(&IO->RecvBuf);
+                       if  (rc == eDBQuery) {
+                               return QueueAnDBOperation(IO);
                        }
                        else {
-                               return rc;
-
+                               IO->NextState = rc;
+                               Finished = StrBufCheckBuffer(&IO->RecvBuf);
                        }
                }
        }
@@ -1239,10 +1254,12 @@ void KillAsyncIOContext(AsyncIO *IO)
        case eReadMore:
        case eReadPayload:
        case eReadFile:
-               QueueEventContext(&Ctx->IO, KillOtherContextNow);
+               IO->ReAttachCB = KillOtherContextNow;
+               QueueAnEventContext(&Ctx->IO);
                break;
        case eDBQuery:
-               QueueDBOperation(&Ctx->IO, KillOtherContextNow);
+               IO->ReAttachCB = KillOtherContextNow;
+               QueueAnDBOperation(&Ctx->IO);
                break;
        case eTerminateConnection:
        case eAbort:
index 8777a34333d9509c2a30f7a134d1c30fb3530ff2..b21e2cc145e8188d71cd6cb91cf01383cbf3da6e 100644 (file)
@@ -193,7 +193,8 @@ struct AsyncIO {
                Timeout,      /* Timeout handler;may also be conn. timeout */
                ConnFail,     /* What to do when one connection failed? */
                ShutdownAbort,/* we're going down. make your piece. */
-               NextDBOperation; /* Perform Database IO */
+               NextDBOperation, /* Perform Database IO */
+               ReAttachCB;   /* on the hop from one Q to the other, this is the next CB */
 
        /* if we have linereaders, maybe we want to read more lines before
         * the real application logic is called? */
@@ -282,7 +283,6 @@ extern int DebugCAres;
 void FreeAsyncIOContents(AsyncIO *IO);
 
 eNextState NextDBOperation(AsyncIO *IO, IO_CallBack CB);
-eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB);
 eNextState EventQueueDBOperation(AsyncIO *IO, IO_CallBack CB, int CloseFDs);
 void StopDBWatchers(AsyncIO *IO);
 eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB);
index 4a27c2482effb42bd47f7cbb99054218d58e63c8..942234afdef080803b4eb519e8ca50d279731c93 100644 (file)
@@ -107,6 +107,8 @@ typedef struct _evcurl_global_data {
 ev_async WakeupCurl;
 evcurl_global_data global;
 
+eNextState QueueAnDBOperation(AsyncIO *IO);
+
 static void
 gotstatus(int nnrun)
 {
@@ -200,6 +202,11 @@ gotstatus(int nnrun)
                        switch(IO->SendDone(IO))
                        {
                        case eDBQuery:
+                               curl_easy_cleanup(IO->HttpReq.chnd);
+                               IO->HttpReq.chnd = NULL;
+                               FreeURL(&IO->ConnectMe);
+                               QueueAnDBOperation(IO);
+                               break;
                        case eSendDNSQuery:
                        case eReadDNSReply:
                        case eConnect: