f20152f8d933319477d08bd571e1163ece28efc0
[citadel.git] / citadel / event_client.h
1 #include <event.h>
2
3 typedef struct AsyncIO AsyncIO;
4
5 typedef enum _eNextState {
6         eSendReply, 
7         eSendMore,
8         eReadMessage, 
9         eTerminateConnection,
10         eAbort
11 }eNextState;
12
13 typedef int (*EventContextAttach)(void *Data);
14 typedef eNextState (*IO_CallBack)(void *Data);
15 typedef eReadState (*IO_LineReaderCallback)(AsyncIO *IO);
16
17 struct AsyncIO {
18         int sock;
19         struct event recv_event, send_event;
20         IOBuffer SendBuf, RecvBuf;
21         IO_LineReaderCallback LineReader;
22         IO_CallBack ReadDone, SendDone, Terminate;
23         StrBuf *IOBuf;
24         void *Data;
25         DeleteHashDataFunc DeleteData; /* data is expected to contain AsyncIO... */
26         eNextState NextState;
27 };
28
29 void FreeAsyncIOContents(AsyncIO *IO);
30
31 int QueueEventContext(void *Ctx, AsyncIO *IO, EventContextAttach CB);
32 int ShutDownEventQueue(void);
33
34 void InitEventIO(AsyncIO *IO, 
35                  void *pData, 
36                  IO_CallBack ReadDone, 
37                  IO_CallBack SendDone, 
38                  IO_CallBack Terminate, 
39                  IO_LineReaderCallback LineReader,
40                  int ReadFirst);