X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fevent_client.h;h=90f5247a61126be23a8a99436f5e9677d01c93cf;hb=72a4e9f304cff9f487b334f0d70f09142fee4183;hp=b2c368db2400c7d6bacd93b8df58a9271ff36c49;hpb=36111d9ace0953d536650249f7339a52b0bed77d;p=citadel.git diff --git a/citadel/event_client.h b/citadel/event_client.h index b2c368db2..90f5247a6 100644 --- a/citadel/event_client.h +++ b/citadel/event_client.h @@ -1,6 +1,26 @@ +/* + * + * Copyright (c) 1998-2012 by the citadel.org team + * + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + #ifndef __EVENT_CLIENT_H__ #define __EVENT_CLIENT_H__ #define EV_COMPAT3 0 +#include "sysconfig.h" #include #include #include @@ -14,13 +34,19 @@ typedef struct AsyncIO AsyncIO; typedef enum _eNextState { eSendDNSQuery, eReadDNSReply, + eDBQuery, + eConnect, - eSendReply, + eSendReply, eSendMore, - eReadMessage, + eSendFile, + + eReadMessage, eReadMore, eReadPayload, + eReadFile, + eTerminateConnection, eAbort }eNextState; @@ -39,7 +65,8 @@ typedef struct __ReadAsyncMsg { long tlen; int dodot; - int flushing; /* if we read maxlen, read until nothing more arives and ignore this. */ + int flushing; +/* if we read maxlen, read until nothing more arives and ignore this. */ int crlf; /* CRLF newlines instead of LF */ } ReadAsyncMsg; @@ -55,33 +82,56 @@ typedef struct _DNSQueryParts { void *Data; } DNSQueryParts; -typedef struct _evcurl_request_data +typedef struct _evcurl_request_data { - CURL *chnd; - struct curl_slist *headers; - char errdesc[CURL_ERROR_SIZE]; + CURL *chnd; + struct curl_slist *headers; + char errdesc[CURL_ERROR_SIZE]; - int attached; + int attached; - char *PlainPostData; - long PlainPostDataLen; - StrBuf *PostData; + char *PlainPostData; + long PlainPostDataLen; + StrBuf *PostData; - StrBuf *ReplyData; - long httpcode; + StrBuf *ReplyData; + long httpcode; } evcurl_request_data; +/* DNS Related */ +typedef struct __evcares_data { + ev_tstamp Start; + 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 { - eNextState NextState; + long ID; + ev_tstamp Now; + ev_tstamp StartIO; + ev_tstamp StartDB; + eNextState NextState; /* connection related */ ParsedURL *ConnectMe; - + /* read/send related... */ StrBuf *IOBuf; - IOBuffer SendBuf, + 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... */ db_abort_by_shutdown; /* server wants to go down... */ @@ -100,28 +150,26 @@ struct AsyncIO { IO_CallBack ReadDone, /* Theres new data to read... */ SendDone, /* we may send more data */ Terminate, /* shutting down... */ - Timeout, /* Timeout handler; may also be connection timeout */ + DBTerminate, /* shutting down... */ + Timeout, /* Timeout handler;may also be conn. timeout */ ConnFail, /* What to do when one connection failed? */ - DNSFail, /* the dns lookup didn't work out. */ - 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? */ + /* if we have linereaders, maybe we want to read more lines before + * the real application logic is called? */ + IO_LineReaderCallback LineReader; + + evcares_data DNS; - /* DNS Related */ - ev_io dns_recv_event, - dns_send_event; - struct ares_options DNSOptions; - ares_channel DNSChannel; - DNSQueryParts *DNSQuery; - 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... */ + + /* Context specific data; Hint: put AsyncIO in there */ void *Data; /* application specific data */ void *CitContext; /* Citadel Session context... */ }; @@ -129,24 +177,78 @@ struct AsyncIO { typedef struct _IOAddHandler { AsyncIO *IO; IO_CallBack EvAttch; -}IOAddHandler; +} IOAddHandler; + + + +extern int DebugEventLoop; +extern int DebugCAres; + +#define EDBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (DebugEventLoop != 0)) + +#define CCID ((CitContext*)IO->CitContext)->cs_pid + +#define EV_syslog(LEVEL, FORMAT, ...) \ + EDBGLOG (LEVEL) syslog(LEVEL, "IO[%ld]CC[%d]" FORMAT, IO->ID, CCID, __VA_ARGS__) + +#define EVM_syslog(LEVEL, FORMAT) \ + EDBGLOG (LEVEL) syslog(LEVEL, "IO[%ld]CC[%d]" FORMAT, IO->ID, CCID) + +#define EVNC_syslog(LEVEL, FORMAT, ...) \ + EDBGLOG (LEVEL) syslog(LEVEL, "IO[%ld]" FORMAT, IO->ID, __VA_ARGS__) + +#define EVNCM_syslog(LEVEL, FORMAT) EDBGLOG (LEVEL) syslog(LEVEL, "IO[%ld]" FORMAT, IO->ID) + + +#define CDBGLOG() if (DebugCAres != 0) +#define EV_DNS_LOG_START(a) \ + CDBGLOG () syslog(LOG_DEBUG, "IO[%ld]CC[%d] + Starting " #a " %p FD %d", IO->ID, CCID, &IO->a, IO->a.fd); \ + EV_backtrace(IO); + +#define EV_DNS_LOG_STOP(a) \ + CDBGLOG () syslog(LOG_DEBUG, "IO[%ld]CC[%d] - Stopping " #a " %p FD %d", IO->ID, CCID, &IO->a, IO->a.fd); \ + EV_backtrace(IO); + +#define EV_DNS_LOG_INIT(a) \ + CDBGLOG () syslog(LOG_DEBUG, "IO[%ld]CC[%d] * Init " #a " %p FD %d", IO->ID, CCID, &IO->a, IO->a.fd); \ + EV_backtrace(IO); + +#define EV_DNS_LOGT_START(a) \ + CDBGLOG () syslog(LOG_DEBUG, "IO[%ld]CC[%d] + Starting " #a " %p", IO->ID, CCID, &IO->a); \ + EV_backtrace(IO); + +#define EV_DNS_LOGT_STOP(a) \ + CDBGLOG () syslog(LOG_DEBUG, "IO[%ld]CC[%d] - Stopping " #a " %p", IO->ID, CCID, &IO->a); \ + EV_backtrace(IO); + +#define EV_DNS_LOGT_INIT(a) \ + CDBGLOG () syslog(LOG_DEBUG, "IO[%ld]CC[%d] * Init " #a " %p", IO->ID, CCID, &IO->a); \ + EV_backtrace(IO); + void FreeAsyncIOContents(AsyncIO *IO); eNextState NextDBOperation(AsyncIO *IO, IO_CallBack CB); eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB); eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB); -int ShutDownEventQueue(void); +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); -void QueueGetHostByName(AsyncIO *IO, const char *Hostname, DNSQueryParts *QueryParts, IO_CallBack PostDNS); +int QueueQuery(ns_type Type, + const char *name, + AsyncIO *IO, + DNSQueryParts *QueryParts, + IO_CallBack PostDNS); + +void QueueGetHostByName(AsyncIO *IO, + const char *Hostname, + DNSQueryParts *QueryParts, + IO_CallBack PostDNS); void QueryCbDone(AsyncIO *IO); @@ -156,28 +258,44 @@ void StopClientWatchers(AsyncIO *IO); void SetNextTimeout(AsyncIO *IO, double timeout); -void InitC_ares_dns(AsyncIO *IO); - #include #define OPT(s, v) \ do { \ - sta = curl_easy_setopt(chnd, (CURLOPT_##s), (v)); \ + sta = curl_easy_setopt(chnd, (CURLOPT_##s), (v)); \ if (sta) { \ - syslog(LOG_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); - -eNextState ReAttachIO(AsyncIO *IO, - void *pData, +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 DBTerminate, + 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 DBTerminate, + IO_CallBack ShutdownAbort); + +eNextState ReAttachIO(AsyncIO *IO, + void *pData, int ReadFirst); -void evcurl_handle_start(AsyncIO *IO); +void EV_backtrace(AsyncIO *IO); +ev_tstamp ctdl_ev_now (void); #endif /* __EVENT_CLIENT_H__ */