e9c1a9d73b777110d7c23a9c5021bd1f13a5c88c
[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
33 void InitEventIO(AsyncIO *IO, 
34                  void *pData, 
35                  IO_CallBack ReadDone, 
36                  IO_CallBack SendDone, 
37                  IO_CallBack Terminate, 
38                  IO_LineReaderCallback LineReader,
39                  int ReadFirst);