]> code.citadel.org Git - citadel.git/blobdiff - citadel/event_client.c
Minor cleanup of rss parser in preparation for some upcoming changes.
[citadel.git] / citadel / event_client.c
index 959aa542d14207c66d294d54174bb3817a244a22..999c9e4546c1b989efc6fb93c6f6ab8df8394b8f 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "ctdl_module.h"
 #include "event_client.h"
+#include "citserver.h"
 
 ConstStr IOStates[] = {
        {HKEY("DB Queue")},
@@ -518,7 +519,10 @@ eReadState HandleInbound(AsyncIO *IO)
                        ev_io_stop(event_base, &IO->recv_event);
                        IO->NextState = IO->ReadDone(IO);
                        if  (IO->NextState == eDBQuery) {
-                               return QueueAnDBOperation(IO);
+                               if (QueueAnDBOperation(IO) == eAbort)
+                                       return eReadFail;
+                               else
+                                       return eReadSuccess;
                        }
                        else {
                                Finished = StrBufCheckBuffer(&IO->RecvBuf);
@@ -559,6 +563,11 @@ IO_send_callback(struct ev_loop *loop, ev_io *watcher, int revents)
                         IO->SendBuf.fd);
 
                fd = fopen(fn, "a+");
+               if (fd == NULL) {
+                       syslog(LOG_EMERG, "failed to open file %s: %s", fn, strerror(errno));
+                       cit_backtrace();
+                       exit(1);
+               }
                fprintf(fd, "Send: BufSize: %ld BufContent: [",
                        nbytes);
                rv = fwrite(pchh, nbytes, 1, fd);
@@ -882,6 +891,11 @@ IO_recv_callback(struct ev_loop *loop, ev_io *watcher, int revents)
                         IO->SendBuf.fd);
 
                fd = fopen(fn, "a+");
+               if (fd == NULL) {
+                       syslog(LOG_EMERG, "failed to open file %s: %s", fn, strerror(errno));
+                       cit_backtrace();
+                       exit(1);
+               }
                fprintf(fd, "Read: BufSize: %ld BufContent: [",
                        nbytes);
                rv = fwrite(pchh, nbytes, 1, fd);
@@ -930,9 +944,18 @@ IO_postdns_callback(struct ev_loop *loop, ev_idle *watcher, int revents)
                case eAbort:
 ////                   StopClientWatchers(IO);
                        ShutDownCLient(IO);
+                       break;
+               case eDBQuery:
+                       StopClientWatchers(IO, 0);
+                       QueueAnDBOperation(IO);
+                       break;
                default:
                        break;
                }
+       case eDBQuery:
+               StopClientWatchers(IO, 0);
+               QueueAnDBOperation(IO);
+               break;
        default:
                break;
        }
@@ -1217,8 +1240,13 @@ eNextState KillOtherContextNow(AsyncIO *IO)
 
        SetEVState(IO, eKill);
 
-       if (Ctx->OtherOne->ShutdownAbort != NULL)
-               Ctx->OtherOne->ShutdownAbort(Ctx->OtherOne);
+       if (Ctx->OtherOne->ShutdownAbort != NULL) {
+               Ctx->OtherOne->NextState = eAbort;
+               if (Ctx->OtherOne->ShutdownAbort(Ctx->OtherOne) == eDBQuery) {
+                       StopClientWatchers(Ctx->OtherOne, 0);
+                       QueueAnDBOperation(Ctx->OtherOne);
+               }
+       }
        return eTerminateConnection;
 }
 
@@ -1257,11 +1285,11 @@ void KillAsyncIOContext(AsyncIO *IO)
        case eReadMore:
        case eReadPayload:
        case eReadFile:
-               IO->ReAttachCB = KillOtherContextNow;
+               Ctx->IO.ReAttachCB = KillOtherContextNow;
                QueueAnEventContext(&Ctx->IO);
                break;
        case eDBQuery:
-               IO->ReAttachCB = KillOtherContextNow;
+               Ctx->IO.ReAttachCB = KillOtherContextNow;
                QueueAnDBOperation(&Ctx->IO);
                break;
        case eTerminateConnection: