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