Libevent Migration
[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         int active_event;
20         struct event recv_event, send_event;
21         IOBuffer SendBuf, RecvBuf;
22         IO_LineReaderCallback LineReader;
23         IO_CallBack ReadDone, SendDone, Terminate;
24         StrBuf *IOBuf;
25         void *Data;
26         DeleteHashDataFunc DeleteData; /* data is expected to contain AsyncIO... */
27         eNextState NextState;
28 };
29
30 typedef struct _IOAddHandler {
31         void *Ctx;
32         EventContextAttach EvAttch;
33 }IOAddHandler; 
34
35 void FreeAsyncIOContents(AsyncIO *IO);
36
37 int QueueEventContext(void *Ctx, AsyncIO *IO, EventContextAttach CB);
38 int ShutDownEventQueue(void);
39
40 void InitEventIO(AsyncIO *IO, 
41                  void *pData, 
42                  IO_CallBack ReadDone, 
43                  IO_CallBack SendDone, 
44                  IO_CallBack Terminate, 
45                  IO_LineReaderCallback LineReader,
46                  int ReadFirst);