]> code.citadel.org Git - citadel.git/blobdiff - citadel/event_client.h
libev migration
[citadel.git] / citadel / event_client.h
index 0fc06b81c21e05002f7678b6a8a7c0d37a9cab54..0e6cae95323fec8a2918ce2db7901c7959cd2b1b 100644 (file)
@@ -1,4 +1,7 @@
-#include <event.h>
+#include <ev.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
 
 typedef struct AsyncIO AsyncIO;
 
@@ -6,6 +9,7 @@ typedef enum _eNextState {
        eSendReply, 
        eSendMore,
        eReadMessage, 
+       eTerminateConnection,
        eAbort
 }eNextState;
 
@@ -14,22 +18,59 @@ typedef eNextState (*IO_CallBack)(void *Data);
 typedef eReadState (*IO_LineReaderCallback)(AsyncIO *IO);
 
 struct AsyncIO {
+       StrBuf *Host;
+       char service[32];
+
+       /* To cycle through several possible services... */
+       struct addrinfo *res;
+       struct addrinfo *curr_ai;
+
+       /* connection related */
        int sock;
-       struct event recv_event, send_event;
-       IOBuffer SendBuf, RecvBuf;
-       IO_LineReaderCallback LineReader;
-       IO_CallBack ReadDone, SendDone;
+       int active_event;
+               eNextState NextState;
+       ev_io recv_event, 
+               send_event, 
+               conn_event;
+       StrBuf *ErrMsg; /* if we fail to connect, or lookup, error goes here. */
+
+       /* read/send related... */
        StrBuf *IOBuf;
-       void *Data;
-       eNextState NextState;
+       IOBuffer SendBuf, 
+               RecvBuf;
+
+       /* Citadel application callbacks... */
+       IO_CallBack ReadDone, /* Theres new data to read... */
+               SendDone,     /* we may send more data */
+               Terminate,    /* shutting down... */
+               Timeout,      /* Timeout handler; may also be connection timeout */
+               ConnFail,     /* What to do when one connection failed? */
+               CustomDNS;    /* If the application wants to do custom dns functionality like cycle through different MX-Records */
+
+       IO_LineReaderCallback LineReader; /* if we have linereaders, maybe we want to read more lines before the real application logic is called? */
+
+       /* Custom data; its expected to contain  AsyncIO so we can save malloc()s... */
+       DeleteHashDataFunc DeleteData; /* so if we have to destroy you, what to do... */
+       void *Data; /* application specific data */
 };
 
+typedef struct _IOAddHandler {
+       void *Ctx;
+       EventContextAttach EvAttch;
+}IOAddHandler; 
+
+void FreeAsyncIOContents(AsyncIO *IO);
 
-int QueueEventContext(void *Ctx, EventContextAttach CB);
+int QueueEventContext(void *Ctx, AsyncIO *IO, EventContextAttach CB);
+int ShutDownEventQueue(void);
 
 void InitEventIO(AsyncIO *IO, 
                 void *pData, 
                 IO_CallBack ReadDone, 
                 IO_CallBack SendDone, 
+                IO_CallBack Terminate, 
+                IO_CallBack Timeout, 
+                IO_CallBack ConnFail, 
+                IO_CallBack CustomDNS,
                 IO_LineReaderCallback LineReader,
                 int ReadFirst);