3 #include <sys/socket.h>
5 #include <arpa/nameser.h>
8 typedef struct AsyncIO AsyncIO;
10 typedef enum _eNextState {
18 typedef eNextState (*IO_CallBack)(AsyncIO *IO);
19 typedef eReadState (*IO_LineReaderCallback)(AsyncIO *IO);
20 typedef void (*ParseDNSAnswerCb)(AsyncIO*, unsigned char*, int);
21 typedef void (*FreeDNSReply)(void *DNSData);
23 typedef struct _DNSQueryParts {
24 ParseDNSAnswerCb DNS_CB;
28 void *VParsedDNSReply;
29 FreeDNSReply DNSReplyFree;
37 /* connection related */
40 /* read/send related... */
46 ev_cleanup abort_by_shutdown; /* server wants to go down... */
47 ev_timer conn_fail, /* connection establishing timed out */
48 rw_timeout; /* timeout while sending data */
49 ev_idle unwind_stack; /* get c-ares out of the stack */
50 ev_io recv_event, /* receive data from the client */
51 send_event, /* send more data to the client */
52 conn_event; /* Connection successfully established */
54 StrBuf *ErrMsg; /* if we fail to connect, or lookup, error goes here. */
56 /* Citadel application callbacks... */
57 IO_CallBack ReadDone, /* Theres new data to read... */
58 SendDone, /* we may send more data */
59 Terminate, /* shutting down... */
60 Timeout, /* Timeout handler; may also be connection timeout */
61 ConnFail, /* What to do when one connection failed? */
62 ShutdownAbort;/* we're going down. make your piece. */
64 IO_LineReaderCallback LineReader; /* if we have linereaders, maybe we want to read more lines before the real application logic is called? */
69 struct ares_options DNSOptions;
70 ares_channel DNSChannel;
71 DNSQueryParts *DNSQuery;
73 /* Custom data; its expected to contain AsyncIO so we can save malloc()s... */
74 void *Data; /* application specific data */
75 void *CitContext; /* Citadel Session context... */
78 typedef struct _IOAddHandler {
83 void FreeAsyncIOContents(AsyncIO *IO);
85 int QueueEventContext(AsyncIO *IO, IO_CallBack CB);
86 int ShutDownEventQueue(void);
88 eNextState InitEventIO(AsyncIO *IO,
91 double first_rw_timeout,
93 void IO_postdns_callback(struct ev_loop *loop, ev_idle *watcher, int revents);
95 int QueueQuery(ns_type Type, const char *name, AsyncIO *IO, DNSQueryParts *QueryParts, IO_CallBack PostDNS);
96 void QueueGetHostByName(AsyncIO *IO, const char *Hostname, DNSQueryParts *QueryParts, IO_CallBack PostDNS);
98 void QueryCbDone(AsyncIO *IO);
100 void StopClient(AsyncIO *IO);
102 void SetNextTimeout(AsyncIO *IO, double timeout);
104 void InitC_ares_dns(AsyncIO *IO);