]> code.citadel.org Git - citadel.git/blobdiff - citadel/event_client.c
Queue functions have to return eNextState in order for the caller to i.e. swap succes...
[citadel.git] / citadel / event_client.c
index 68e59cc1f11a36da456117a8d2b506b70e4a4f43..669a0e0aec6c76cfbde6d729aa9aa40f7067a890 100644 (file)
@@ -87,7 +87,7 @@ extern struct ev_loop *event_db;
 extern ev_async DBAddJob;   
 extern ev_async DBExitEventLoop;
 
-int QueueDBOperation(AsyncIO *IO, IO_CallBack CB)
+eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB)
 {
        IOAddHandler *h;
        int i;
@@ -108,7 +108,7 @@ int QueueDBOperation(AsyncIO *IO, IO_CallBack CB)
 
        ev_async_send (event_db, &DBAddJob);
        CtdlLogPrintf(CTDL_DEBUG, "DBEVENT Q Done.\n");
-       return 0;
+       return eDBQuery;
 }
 
 void ShutDownDBCLient(AsyncIO *IO)
@@ -177,7 +177,7 @@ extern ev_async AddJob;
 extern ev_async ExitEventLoop;
 
 
-int QueueEventContext(AsyncIO *IO, IO_CallBack CB)
+eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB)
 {
        IOAddHandler *h;
        int i;
@@ -198,7 +198,7 @@ int QueueEventContext(AsyncIO *IO, IO_CallBack CB)
 
        ev_async_send (event_base, &AddJob);
        CtdlLogPrintf(CTDL_DEBUG, "EVENT Q Done.\n");
-       return 0;
+       return eSendReply;
 }
 
 int ShutDownEventQueue(void)
@@ -227,15 +227,12 @@ void StopClientWatchers(AsyncIO *IO)
        ev_io_stop(event_base, &IO->conn_event);
        ev_idle_stop(event_base, &IO->unwind_stack);
 
-       if (IO->SendBuf.fd != 0)
-       {
-               ev_io_stop(event_base, &IO->send_event);
-               ev_io_stop(event_base, &IO->recv_event);
-               ev_timer_stop (event_base, &IO->rw_timeout);
-               close(IO->SendBuf.fd);
-               IO->SendBuf.fd = 0;
-               IO->RecvBuf.fd = 0;
-       }
+       ev_io_stop(event_base, &IO->send_event);
+       ev_io_stop(event_base, &IO->recv_event);
+       ev_timer_stop (event_base, &IO->rw_timeout);
+       close(IO->SendBuf.fd);
+       IO->SendBuf.fd = 0;
+       IO->RecvBuf.fd = 0;
 }
 
 void ShutDownCLient(AsyncIO *IO)
@@ -284,7 +281,6 @@ eReadState HandleInbound(AsyncIO *IO)
                                
                        switch (Finished) {
                        case eMustReadMore: /// read new from socket... 
-                               return Finished;
                                break;
                        case eBufferNotEmpty: /* shouldn't happen... */
                        case eReadSuccess: /// done for now...
@@ -355,48 +351,21 @@ IO_send_callback(struct ev_loop *loop, ev_io *watcher, int revents)
                         IO->SendBuf.fd);
                
                fd = fopen(fn, "a+");
-               fprintf(fd, "Read: BufSize: %ld BufContent: [",
+               fprintf(fd, "Send: BufSize: %ld BufContent: [",
                        nbytes);
                rv = fwrite(pchh, nbytes, 1, fd);
                if (!rv) printf("failed to write debug to %s!\n", fn);
                fprintf(fd, "]\n");
-               
-               
-               fclose(fd);
-       }
 #endif
-       rc = StrBuf_write_one_chunk_callback(watcher->fd, 0/*TODO*/, &IO->SendBuf);
+               rc = StrBuf_write_one_chunk_callback(watcher->fd, 0/*TODO*/, &IO->SendBuf);
 
-       if (rc == 0)
-       {               
 #ifdef BIGBAD_IODBG
-               {
-                       int rv = 0;
-                       char fn [SIZ];
-                       FILE *fd;
-                       const char *pch = ChrPtr(IO->SendBuf.Buf);
-                       const char *pchh = IO->SendBuf.ReadWritePointer;
-                       long nbytes;
-
-                       if (pchh == NULL)
-                               pchh = pch;
-                       
-                       nbytes = StrLength(IO->SendBuf.Buf) - (pchh - pch);
-                       snprintf(fn, SIZ, "/tmp/foolog_ev_%s.%d", 
-                                ((CitContext*)(IO->CitContext))->ServiceName, 
-                                IO->SendBuf.fd);
-               
-                       fd = fopen(fn, "a+");
-                       fprintf(fd, "Read: BufSize: %ld BufContent: [",
-                               nbytes);
-                       rv = fwrite(pchh, nbytes, 1, fd);
-                       if (!rv) printf("failed to write debug to %s!\n", fn);
-                       fprintf(fd, "]\n");
-               
-                       
-                       fclose(fd);
-               }
+               fprintf(fd, "Sent: BufSize: %d bytes.\n", rc);
+               fclose(fd);
+       }
 #endif
+       if (rc == 0)
+       {
                ev_io_stop(event_base, &IO->send_event);
                switch (IO->NextState) {
                case eSendMore: