X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fevent_client.h;h=9c4fd2ba143806ce50bc529f6f94e8048e4d4c38;hb=c855d497545dad80942a194624c111a54cd1fdc7;hp=5939ad914ce96db005e862437ab3f83220d02ec7;hpb=67d954e97ccee1cd9c9ae8a969eece1383a04d46;p=citadel.git diff --git a/citadel/event_client.h b/citadel/event_client.h index 5939ad914..9c4fd2ba1 100644 --- a/citadel/event_client.h +++ b/citadel/event_client.h @@ -1,4 +1,7 @@ +#ifndef __EVENT_CLIENT_H__ +#define __EVENT_CLIENT_H__ #define EV_COMPAT3 0 +#include "sysconfig.h" #include #include #include @@ -12,10 +15,19 @@ typedef struct AsyncIO AsyncIO; typedef enum _eNextState { eSendDNSQuery, eReadDNSReply, + + eDBQuery, + eConnect, eSendReply, eSendMore, + eSendFile, + eReadMessage, + eReadMore, + eReadPayload, + eReadFile, + eTerminateConnection, eAbort }eNextState; @@ -25,6 +37,21 @@ typedef eReadState (*IO_LineReaderCallback)(AsyncIO *IO); 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; @@ -51,7 +78,23 @@ typedef struct _evcurl_request_data long httpcode; } evcurl_request_data; +/* DNS Related */ +typedef struct __evcares_data { + ev_io recv_event, + send_event; + ev_timer timeout; /* timeout while requesting ips */ +#ifdef DEBUG_CARES + short int SourcePort; +#endif + struct ares_options Options; + ares_channel Channel; + DNSQueryParts *Query; + + IO_CallBack Fail; /* the dns lookup didn't work out. */ +} evcares_data; + struct AsyncIO { + long ID; eNextState NextState; /* connection related */ @@ -62,11 +105,15 @@ struct AsyncIO { 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 */ @@ -80,23 +127,20 @@ struct AsyncIO { 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. */ + 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? */ - /* DNS Related */ - ev_io dns_recv_event, - dns_send_event; - struct ares_options DNSOptions; - ares_channel DNSChannel; - DNSQueryParts *DNSQuery; - + evcares_data DNS; + evcurl_request_data HttpReq; /* Saving / loading a message async from / to disk */ - + ReadAsyncMsg *ReadMsg; struct CtdlMessage *AsyncMsg; 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... */ @@ -107,18 +151,24 @@ typedef struct _IOAddHandler { IO_CallBack EvAttch; }IOAddHandler; +#define CCID ((CitContext*)IO->CitContext)->cs_pid +#define EV_syslog(LEVEL, FORMAT, ...) syslog(LEVEL, "IO[%ld]CC[%d]" FORMAT, IO->ID, CCID, __VA_ARGS__) +#define EVM_syslog(LEVEL, FORMAT) syslog(LEVEL, "IO[%ld]CC[%d]" FORMAT, IO->ID, CCID) + +#define EVNC_syslog(LEVEL, FORMAT, ...) syslog(LEVEL, "IO[%ld]" FORMAT, IO->ID, __VA_ARGS__) +#define EVNCM_syslog(LEVEL, FORMAT) syslog(LEVEL, "IO[%ld]" FORMAT, IO->ID) + void FreeAsyncIOContents(AsyncIO *IO); -void NextDBOperation(AsyncIO *IO, IO_CallBack CB); -int QueueDBOperation(AsyncIO *IO, IO_CallBack CB); -int QueueEventContext(AsyncIO *IO, IO_CallBack CB); -int ShutDownEventQueue(void); +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); -eNextState InitEventIO(AsyncIO *IO, - void *pData, - double conn_timeout, - double first_rw_timeout, - int ReadFirst); +eNextState EvConnectSock(AsyncIO *IO, + double conn_timeout, + double first_rw_timeout, + int ReadFirst); void IO_postdns_callback(struct ev_loop *loop, ev_idle *watcher, int revents); int QueueQuery(ns_type Type, const char *name, AsyncIO *IO, DNSQueryParts *QueryParts, IO_CallBack PostDNS); @@ -140,14 +190,30 @@ void InitC_ares_dns(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 Terminate); - -void evcurl_handle_start(AsyncIO *IO); +void InitIOStruct(AsyncIO *IO, + void *Data, + eNextState NextState, + IO_LineReaderCallback LineReader, + IO_CallBack DNS_Fail, + IO_CallBack SendDone, + IO_CallBack ReadDone, + IO_CallBack Terminate, + IO_CallBack ConnFail, + IO_CallBack Timeout, + IO_CallBack ShutdownAbort); + +int InitcURLIOStruct(AsyncIO *IO, + void *Data, + const char* Desc, + IO_CallBack SendDone, + IO_CallBack Terminate, + IO_CallBack ShutdownAbort); + +eNextState ReAttachIO(AsyncIO *IO, + void *pData, + int ReadFirst); + +#endif /* __EVENT_CLIENT_H__ */