+#ifndef __EVENT_CLIENT_H__
+#define __EVENT_CLIENT_H__
+#define EV_COMPAT3 0
#include <ev.h>
#include <sys/types.h>
#include <sys/socket.h>
typedef enum _eNextState {
eSendDNSQuery,
eReadDNSReply,
+
+ eDBQuery,
+
eConnect,
eSendReply,
eSendMore,
+ eSendFile,
+
eReadMessage,
+ eReadMore,
+ eReadPayload,
+ eReadFile,
+
eTerminateConnection,
eAbort
}eNextState;
typedef void (*ParseDNSAnswerCb)(AsyncIO*, unsigned char*, int);
typedef void (*FreeDNSReply)(void *DNSData);
+
+typedef struct __ReadAsyncMsg {
+ StrBuf *MsgBuf;
+ size_t maxlen; /* maximum message length */
+
+ const char *terminator; /* token signalling EOT */
+ long tlen;
+ int dodot;
+
+ int flushing; /* if we read maxlen, read until nothing more arives and ignore this. */
+
+ int crlf; /* CRLF newlines instead of LF */
+} ReadAsyncMsg;
+
+
typedef struct _DNSQueryParts {
ParseDNSAnswerCb DNS_CB;
IO_CallBack PostDNS;
IOBuffer SendBuf,
RecvBuf;
+ FDIOBuffer IOB; /* when sending from / reading into files, this is used. */
+
/* our events... */
- ev_cleanup abort_by_shutdown; /* server wants to go down... */
+ ev_cleanup abort_by_shutdown, /* server wants to go down... */
+ db_abort_by_shutdown; /* server wants to go down... */
ev_timer conn_fail, /* connection establishing timed out */
rw_timeout; /* timeout while sending data */
ev_idle unwind_stack, /* get c-ares out of the stack */
+ db_unwind_stack, /* wait for next db operation... */
conn_fail_immediate; /* unwind stack, but fail immediately. */
ev_io recv_event, /* receive data from the client */
send_event, /* send more data to the client */
Terminate, /* shutting down... */
Timeout, /* Timeout handler; may also be connection timeout */
ConnFail, /* What to do when one connection failed? */
- ShutdownAbort;/* we're going down. make your piece. */
+ DNSFail, /* the dns lookup didn't work out. */
+ ShutdownAbort,/* we're going down. make your piece. */
+ NextDBOperation; /* Perform Database IO */
IO_LineReaderCallback LineReader; /* if we have linereaders, maybe we want to read more lines before the real application logic is called? */
evcurl_request_data HttpReq;
/* Saving / loading a message async from / to disk */
-
+ ReadAsyncMsg *ReadMsg;
struct CtdlMessage *AsyncMsg;
- struct recptypes AsyncRcp;
+ struct recptypes *AsyncRcp;
/* Custom data; its expected to contain AsyncIO so we can save malloc()s... */
void *Data; /* application specific data */
void *CitContext; /* Citadel Session context... */
void FreeAsyncIOContents(AsyncIO *IO);
-int QueueEventContext(AsyncIO *IO, IO_CallBack CB);
+eNextState NextDBOperation(AsyncIO *IO, IO_CallBack CB);
+eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB);
+eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB);
+eNextState QueueCurlContext(AsyncIO *IO);
int ShutDownEventQueue(void);
eNextState InitEventIO(AsyncIO *IO,
do { \
sta = curl_easy_setopt(chnd, (CURLOPT_##s), (v)); \
if (sta) { \
- CtdlLogPrintf(CTDL_ERR, "error setting option " #s " on curl handle: %s", curl_easy_strerror(sta)); \
+ syslog(LOG_ERR, "error setting option " #s " on curl handle: %s", curl_easy_strerror(sta)); \
} } while (0)
int evcurl_init(AsyncIO *IO,
void *CustomData,
const char* Desc,
- IO_CallBack CallBack);
+ IO_CallBack CallBack,
+ IO_CallBack Terminate);
+
+eNextState ReAttachIO(AsyncIO *IO,
+ void *pData,
+ int ReadFirst);
-void evcurl_handle_start(AsyncIO *IO);
+#endif /* __EVENT_CLIENT_H__ */