Back to index

citadel  8.12
Classes | Defines | Typedefs | Enumerations | Functions | Variables
event_client.h File Reference
#include "sysconfig.h"
#include <ev.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/nameser.h>
#include <ares.h>
#include <curl/curl.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  __ReadAsyncMsg
struct  _DNSQueryParts
struct  _evcurl_request_data
struct  __evcares_data
struct  AsyncIO
struct  _IOAddHandler

Defines

#define EV_COMPAT3   0
#define EDBGLOG(LEVEL)   if ((LEVEL != LOG_DEBUG) || (DebugEventLoop != 0))
#define CCID   ((CitContext*)IO->CitContext)->cs_pid
#define EVQ_syslog(LEVEL, FORMAT,...)   EDBGLOG (LEVEL) syslog(LEVEL, "IOQ " FORMAT, __VA_ARGS__)
#define EVQM_syslog(LEVEL, FORMAT)   EDBGLOG (LEVEL) syslog(LEVEL, "IO " FORMAT)
#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 CEDBGLOG(LEVEL)   if ((LEVEL != LOG_DEBUG) || (DebugCAres != 0))
#define EV_DNS_LOG_START(a)
#define EV_DNS_LOG_STOP(a)
#define EV_DNS_LOG_INIT(a)
#define EV_DNS_LOGT_START(a)
#define EV_DNS_LOGT_STOP(a)
#define EV_DNS_LOGT_INIT(a)
#define EV_DNS_syslog(LEVEL, FORMAT,...)   CEDBGLOG (LEVEL) syslog(LEVEL, "IO[%ld]CC[%d] " FORMAT, IO->ID, CCID, __VA_ARGS__)
#define EVM_DNS_syslog(LEVEL, FORMAT)   CEDBGLOG (LEVEL) syslog(LEVEL, "IO[%ld]CC[%d] " FORMAT, IO->ID, CCID)
#define OPT(s, v)

Typedefs

typedef struct AsyncIO
typedef enum _eNextState eNextState
typedef eNextState(* IO_CallBack )(AsyncIO *IO)
typedef eReadState(* IO_LineReaderCallback )(AsyncIO *IO)
typedef void(* ParseDNSAnswerCb )(AsyncIO *, unsigned char *, int)
typedef void(* FreeDNSReply )(void *DNSData)
typedef struct __ReadAsyncMsg ReadAsyncMsg
typedef struct _DNSQueryParts DNSQueryParts
typedef struct _evcurl_request_data evcurl_request_data
typedef struct __evcares_data evcares_data
typedef struct _IOAddHandler IOAddHandler

Enumerations

enum  _eNextState {
  eSendDNSQuery, eReadDNSReply, eDBQuery, eConnect,
  eSendReply, eSendMore, eSendFile, eReadMessage,
  eReadMore, eReadPayload, eReadFile, eTerminateConnection,
  eAbort
}

Functions

void FreeAsyncIOContents (AsyncIO *IO)
eNextState NextDBOperation (AsyncIO *IO, IO_CallBack CB)
eNextState QueueDBOperation (AsyncIO *IO, IO_CallBack CB)
void StopDBWatchers (AsyncIO *IO)
eNextState QueueEventContext (AsyncIO *IO, IO_CallBack CB)
eNextState QueueCurlContext (AsyncIO *IO)
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)
void QueryCbDone (AsyncIO *IO)
void StopClient (AsyncIO *IO)
void StopClientWatchers (AsyncIO *IO, int CloseFD)
void SetNextTimeout (AsyncIO *IO, double timeout)
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)
void StopCurlWatchers (AsyncIO *IO)
eNextState ReAttachIO (AsyncIO *IO, void *pData, int ReadFirst)
void EV_backtrace (AsyncIO *IO)
ev_tstamp ctdl_ev_now (void)

Variables

int DebugEventLoop
int DebugCAres

Class Documentation

struct __ReadAsyncMsg

Definition at line 60 of file event_client.h.

Class Members
int crlf
int dodot
int flushing
size_t maxlen
StrBuf * MsgBuf
const char * terminator
long tlen
struct _DNSQueryParts

Definition at line 75 of file event_client.h.

Collaboration diagram for _DNSQueryParts:
Class Members
void * Data
ParseDNSAnswerCb DNS_CB
FreeDNSReply DNSReplyFree
int DNSStatus
IO_CallBack PostDNS
void * VParsedDNSReply
struct _evcurl_request_data

Definition at line 85 of file event_client.h.

Class Members
int attached
CURL * chnd
char errdesc
struct curl_slist * headers
long httpcode
char * PlainPostData
long PlainPostDataLen
StrBuf * PostData
StrBuf * ReplyData
struct __evcares_data

Definition at line 102 of file event_client.h.

Collaboration diagram for __evcares_data:
Class Members
ares_channel Channel
IO_CallBack Fail
DNSQueryParts * Query
ev_io recv_event
ev_io send_event
short int SourcePort
ev_tstamp Start
ev_timer timeout
struct AsyncIO

Definition at line 116 of file event_client.h.

Collaboration diagram for AsyncIO:
Class Members
ev_cleanup abort_by_shutdown
struct CtdlMessage * AsyncMsg
struct recptypes * AsyncRcp
void * CitContext
ev_io conn_event
ev_timer conn_fail
ev_idle conn_fail_immediate
ParsedURL * ConnectMe
IO_CallBack ConnFail
void * Data
ev_cleanup db_abort_by_shutdown
ev_idle db_unwind_stack
IO_CallBack DBTerminate
evcares_data DNS
StrBuf * ErrMsg
evcurl_request_data HttpReq
long ID
FDIOBuffer IOB
StrBuf * IOBuf
IO_LineReaderCallback LineReader
IO_CallBack NextDBOperation
eNextState NextState
ev_tstamp Now
IO_CallBack ReadDone
ReadAsyncMsg * ReadMsg
ev_io recv_event
IOBuffer RecvBuf
ev_timer rw_timeout
ev_io send_event
IOBuffer SendBuf
IO_CallBack SendDone
IO_CallBack ShutdownAbort
ev_tstamp StartDB
ev_tstamp StartIO
IO_CallBack Terminate
IO_CallBack Timeout
ev_idle unwind_stack
struct _IOAddHandler

Definition at line 176 of file event_client.h.

Collaboration diagram for _IOAddHandler:
Class Members
IO_CallBack EvAttch
AsyncIO * IO

Define Documentation

#define CCID   ((CitContext*)IO->CitContext)->cs_pid

Definition at line 188 of file event_client.h.

#define CDBGLOG ( )    if (DebugCAres != 0)

Definition at line 208 of file event_client.h.

#define CEDBGLOG (   LEVEL)    if ((LEVEL != LOG_DEBUG) || (DebugCAres != 0))

Definition at line 209 of file event_client.h.

#define EDBGLOG (   LEVEL)    if ((LEVEL != LOG_DEBUG) || (DebugEventLoop != 0))

Definition at line 186 of file event_client.h.

#define EV_COMPAT3   0

Definition at line 22 of file event_client.h.

#define EV_DNS_LOG_INIT (   a)
Value:
CDBGLOG () { syslog(LOG_DEBUG, "IO[%ld]CC[%d] * Init " #a " %s %p FD %d", IO->ID, CCID, __FUNCTION__, &IO->a, IO->a.fd); \
                   EV_backtrace(IO);}

Definition at line 218 of file event_client.h.

#define EV_DNS_LOG_START (   a)
Value:
CDBGLOG () {syslog(LOG_DEBUG, "IO[%ld]CC[%d] + Starting " #a " %s %p FD %d", IO->ID, CCID, __FUNCTION__, &IO->a, IO->a.fd); \
                  EV_backtrace(IO);}

Definition at line 210 of file event_client.h.

#define EV_DNS_LOG_STOP (   a)
Value:
CDBGLOG () { syslog(LOG_DEBUG, "IO[%ld]CC[%d] - Stopping " #a " %s %p FD %d", IO->ID, CCID, __FUNCTION__, &IO->a, IO->a.fd); \
                   EV_backtrace(IO);}

Definition at line 214 of file event_client.h.

#define EV_DNS_LOGT_INIT (   a)
Value:
CDBGLOG () { syslog(LOG_DEBUG, "IO[%ld]CC[%d] * Init " #a " %p", IO->ID, CCID, &IO->a); \
                   EV_backtrace(IO);}

Definition at line 230 of file event_client.h.

#define EV_DNS_LOGT_START (   a)
Value:
CDBGLOG () { syslog(LOG_DEBUG, "IO[%ld]CC[%d] + Starting " #a " %s %p", IO->ID, CCID, __FUNCTION__, &IO->a); \
                   EV_backtrace(IO);}

Definition at line 222 of file event_client.h.

#define EV_DNS_LOGT_STOP (   a)
Value:
CDBGLOG () { syslog(LOG_DEBUG, "IO[%ld]CC[%d] - Stopping " #a " %s %p", IO->ID, CCID, __FUNCTION__, &IO->a); \
                   EV_backtrace(IO); }

Definition at line 226 of file event_client.h.

#define EV_DNS_syslog (   LEVEL,
  FORMAT,
  ... 
)    CEDBGLOG (LEVEL) syslog(LEVEL, "IO[%ld]CC[%d] " FORMAT, IO->ID, CCID, __VA_ARGS__)

Definition at line 234 of file event_client.h.

#define EV_syslog (   LEVEL,
  FORMAT,
  ... 
)    EDBGLOG (LEVEL) syslog(LEVEL, "IO[%ld]CC[%d] " FORMAT, IO->ID, CCID, __VA_ARGS__)

Definition at line 196 of file event_client.h.

#define EVM_DNS_syslog (   LEVEL,
  FORMAT 
)    CEDBGLOG (LEVEL) syslog(LEVEL, "IO[%ld]CC[%d] " FORMAT, IO->ID, CCID)

Definition at line 237 of file event_client.h.

#define EVM_syslog (   LEVEL,
  FORMAT 
)    EDBGLOG (LEVEL) syslog(LEVEL, "IO[%ld]CC[%d] " FORMAT, IO->ID, CCID)

Definition at line 199 of file event_client.h.

#define EVNC_syslog (   LEVEL,
  FORMAT,
  ... 
)    EDBGLOG (LEVEL) syslog(LEVEL, "IO[%ld] " FORMAT, IO->ID, __VA_ARGS__)

Definition at line 202 of file event_client.h.

#define EVNCM_syslog (   LEVEL,
  FORMAT 
)    EDBGLOG (LEVEL) syslog(LEVEL, "IO[%ld]" FORMAT, IO->ID)

Definition at line 205 of file event_client.h.

#define EVQ_syslog (   LEVEL,
  FORMAT,
  ... 
)    EDBGLOG (LEVEL) syslog(LEVEL, "IOQ " FORMAT, __VA_ARGS__)

Definition at line 190 of file event_client.h.

#define EVQM_syslog (   LEVEL,
  FORMAT 
)    EDBGLOG (LEVEL) syslog(LEVEL, "IO " FORMAT)

Definition at line 193 of file event_client.h.

#define OPT (   s,
 
)
Value:
do { \
              sta = curl_easy_setopt(chnd, (CURLOPT_##s), (v));       \
              if (sta)  {                                      \
                     EVQ_syslog(LOG_ERR,                       \
                            "error setting option " #s         \
                            " on curl handle: %s",                    \
                            curl_easy_strerror(sta));          \
       } } while (0)

Definition at line 275 of file event_client.h.


Typedef Documentation

typedef struct AsyncIO

Definition at line 32 of file event_client.h.

typedef struct _DNSQueryParts DNSQueryParts
typedef enum _eNextState eNextState
typedef struct __evcares_data evcares_data
typedef void(* FreeDNSReply)(void *DNSData)

Definition at line 57 of file event_client.h.

typedef eNextState(* IO_CallBack)(AsyncIO *IO)

Definition at line 54 of file event_client.h.

typedef eReadState(* IO_LineReaderCallback)(AsyncIO *IO)

Definition at line 55 of file event_client.h.

typedef struct _IOAddHandler IOAddHandler
typedef void(* ParseDNSAnswerCb)(AsyncIO *, unsigned char *, int)

Definition at line 56 of file event_client.h.

typedef struct __ReadAsyncMsg ReadAsyncMsg

Enumeration Type Documentation

Enumerator:
eSendDNSQuery 
eReadDNSReply 
eDBQuery 
eConnect 
eSendReply 
eSendMore 
eSendFile 
eReadMessage 
eReadMore 
eReadPayload 
eReadFile 
eTerminateConnection 
eAbort 

Definition at line 34 of file event_client.h.


Function Documentation

ev_tstamp ctdl_ev_now ( void  )

Definition at line 1116 of file event_client.c.

{
       return ev_now(event_base);
}
void EV_backtrace ( AsyncIO IO)

Definition at line 1092 of file event_client.c.

{
#ifdef HAVE_BACKTRACE
       void *stack_frames[50];
       size_t size, i;
       char **strings;

       if ((IO == NULL) || (DebugEventLoopBacktrace == 0))
              return;
       size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
       strings = backtrace_symbols(stack_frames, size);
       for (i = 0; i < size; i++) {
              if (strings != NULL) {
                     EV_syslog(LOG_ALERT, " BT %s\n", strings[i]);
              }
              else {
                     EV_syslog(LOG_ALERT, " BT %p\n", stack_frames[i]);
              }
       }
       free(strings);
#endif
}
eNextState EvConnectSock ( AsyncIO IO,
double  conn_timeout,
double  first_rw_timeout,
int  ReadFirst 
)

Definition at line 858 of file event_client.c.

{
       struct sockaddr_in egress_sin;
       int fdflags;
       int rc = -1;

       become_session(IO->CitContext);

       if (ReadFirst) {
              IO->NextState = eReadMessage;
       }
       else {
              IO->NextState = eSendReply;
       }

       IO->SendBuf.fd = IO->RecvBuf.fd =
              socket(
                     (IO->ConnectMe->IPv6)?PF_INET6:PF_INET,
                     SOCK_STREAM,
                     IPPROTO_TCP);

       if (IO->SendBuf.fd < 0) {
              EV_syslog(LOG_ERR,
                       "EVENT: socket() failed: %s\n",
                       strerror(errno));

              StrBufPrintf(IO->ErrMsg,
                          "Failed to create socket: %s",
                          strerror(errno));
              IO->SendBuf.fd = IO->RecvBuf.fd = 0;
              return eAbort;
       }
       fdflags = fcntl(IO->SendBuf.fd, F_GETFL);
       if (fdflags < 0) {
              EV_syslog(LOG_ERR,
                       "EVENT: unable to get socket flags! %s \n",
                       strerror(errno));
              StrBufPrintf(IO->ErrMsg,
                          "Failed to get socket flags: %s",
                          strerror(errno));
              close(IO->SendBuf.fd);
              IO->SendBuf.fd = IO->RecvBuf.fd = 0;
              return eAbort;
       }
       fdflags = fdflags | O_NONBLOCK;
       if (fcntl(IO->SendBuf.fd, F_SETFL, fdflags) < 0) {
              EV_syslog(
                     LOG_ERR,
                     "EVENT: unable to set socket nonblocking flags! %s \n",
                     strerror(errno));
              StrBufPrintf(IO->ErrMsg,
                          "Failed to set socket flags: %s",
                          strerror(errno));
              close(IO->SendBuf.fd);
              IO->SendBuf.fd = IO->RecvBuf.fd = 0;
              return eAbort;
       }
/* TODO: maye we could use offsetof() to calc the position of data...
 * http://doc.dvgu.ru/devel/ev.html#associating_custom_data_with_a_watcher
 */
       ev_io_init(&IO->recv_event, IO_recv_callback, IO->RecvBuf.fd, EV_READ);
       IO->recv_event.data = IO;
       ev_io_init(&IO->send_event, IO_send_callback, IO->SendBuf.fd, EV_WRITE);
       IO->send_event.data = IO;

       ev_timer_init(&IO->conn_fail, IO_connfail_callback, conn_timeout, 0);
       IO->conn_fail.data = IO;
       ev_timer_init(&IO->rw_timeout, IO_Timeout_callback, first_rw_timeout,0);
       IO->rw_timeout.data = IO;




       /* for debugging you may bypass it like this:
        * IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1");
        * ((struct sockaddr_in)IO->ConnectMe->Addr).sin_addr.s_addr =
        *   inet_addr("127.0.0.1");
        */
       if (IO->ConnectMe->IPv6) {
              rc = connect(IO->SendBuf.fd,
                          &IO->ConnectMe->Addr,
                          sizeof(struct sockaddr_in6));
       }
       else {
              /* If citserver is bound to a specific IP address on the host, make
               * sure we use that address for outbound connections.
               */
       
              memset(&egress_sin, 0, sizeof(egress_sin));
              egress_sin.sin_family = AF_INET;
              if (!IsEmptyStr(config.c_ip_addr)) {
                     egress_sin.sin_addr.s_addr = inet_addr(config.c_ip_addr);
                     if (egress_sin.sin_addr.s_addr == !INADDR_ANY) {
                            egress_sin.sin_addr.s_addr = INADDR_ANY;
                     }

                     /* If this bind fails, no problem; we can still use INADDR_ANY */
                     bind(IO->SendBuf.fd, (struct sockaddr *)&egress_sin, sizeof(egress_sin));
              }
              rc = connect(IO->SendBuf.fd,
                          (struct sockaddr_in *)&IO->ConnectMe->Addr,
                          sizeof(struct sockaddr_in));
       }

       if (rc >= 0){
              EVM_syslog(LOG_DEBUG, "connect() immediate success.\n");
              set_start_callback(event_base, IO, 0);
              return IO->NextState;
       }
       else if (errno == EINPROGRESS) {
              EVM_syslog(LOG_DEBUG, "connect() have to wait now.\n");

              ev_io_init(&IO->conn_event,
                        IO_connestd_callback,
                        IO->SendBuf.fd,
                        EV_READ|EV_WRITE);

              IO->conn_event.data = IO;

              ev_io_start(event_base, &IO->conn_event);
              ev_timer_start(event_base, &IO->conn_fail);
              return IO->NextState;
       }
       else {
              ev_idle_init(&IO->conn_fail_immediate,
                          IO_connfailimmediate_callback);
              IO->conn_fail_immediate.data = IO;
              ev_idle_start(event_base, &IO->conn_fail_immediate);

              EV_syslog(LOG_ERR, "connect() failed: %s\n", strerror(errno));
              StrBufPrintf(IO->ErrMsg,
                          "Failed to connect: %s",
                          strerror(errno));
              return IO->NextState;
       }
       return IO->NextState;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void FreeAsyncIOContents ( AsyncIO IO)

Definition at line 292 of file event_client.c.

{
       CitContext *Ctx = IO->CitContext;

       FreeStrBuf(&IO->IOBuf);
       FreeStrBuf(&IO->SendBuf.Buf);
       FreeStrBuf(&IO->RecvBuf.Buf);

       DestructCAres(IO);

       FreeURL(&IO->ConnectMe);
       FreeStrBuf(&IO->HttpReq.ReplyData);

       if (Ctx) {
              Ctx->state = CON_IDLE;
              Ctx->kill_me = 1;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int InitcURLIOStruct ( AsyncIO IO,
void *  Data,
const char *  Desc,
IO_CallBack  SendDone,
IO_CallBack  Terminate,
IO_CallBack  DBTerminate,
IO_CallBack  ShutdownAbort 
)

Definition at line 1066 of file event_client.c.

{
       IO->Data          = Data;

       IO->CitContext    = CloneContext(CC);
       ((CitContext *)IO->CitContext)->session_specific_data = (char*) Data;

       IO->SendDone      = SendDone;
       IO->Terminate     = Terminate;
       IO->DBTerminate   = DBTerminate;
       IO->ShutdownAbort = ShutdownAbort;

       strcpy(IO->HttpReq.errdesc, Desc);


       return  evcurl_init(IO);

}

Here is the call graph for this function:

Here is the caller graph for this function:

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 
)

Definition at line 1024 of file event_client.c.

{
       IO->Data          = Data;

       IO->CitContext    = CloneContext(CC);
       ((CitContext *)IO->CitContext)->session_specific_data = (char*) Data;

       IO->NextState     = NextState;

       IO->SendDone      = SendDone;
       IO->ReadDone      = ReadDone;
       IO->Terminate     = Terminate;
       IO->DBTerminate   = DBTerminate;
       IO->LineReader    = LineReader;
       IO->ConnFail      = ConnFail;
       IO->Timeout       = Timeout;
       IO->ShutdownAbort = ShutdownAbort;

       IO->DNS.Fail      = DNS_Fail;

       IO->SendBuf.Buf   = NewStrBufPlain(NULL, 1024);
       IO->RecvBuf.Buf   = NewStrBufPlain(NULL, 1024);
       IO->IOBuf         = NewStrBuf();
       EV_syslog(LOG_DEBUG,
                "EVENT: Session lives at %p IO at %p \n",
                Data, IO);

}

Here is the call graph for this function:

Here is the caller graph for this function:

void IO_postdns_callback ( struct ev_loop *  loop,
ev_idle *  watcher,
int  revents 
)

Definition at line 834 of file event_client.c.

{
       AsyncIO *IO = watcher->data;
       IO->Now = ev_now(event_base);
       EV_syslog(LOG_DEBUG, "event: %s\n", __FUNCTION__);
       become_session(IO->CitContext);
       assert(IO->DNS.Query->PostDNS);
       switch (IO->DNS.Query->PostDNS(IO))
       {
       case eAbort:
              assert(IO->DNS.Fail);
              switch (IO->DNS.Fail(IO)) {
              case eAbort:
                     ShutDownCLient(IO);
              default:
                     break;
              }
       default:
              break;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 183 of file event_client.c.

{
       IO->NextDBOperation = CB;
       ev_idle_init(&IO->db_unwind_stack,
                   DB_PerformNext);
       IO->db_unwind_stack.data = IO;
       ev_idle_start(event_db, &IO->db_unwind_stack);
       return eDBQuery;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void QueryCbDone ( AsyncIO IO)

Definition at line 295 of file serv_c-ares-dns.c.

{
       EV_DNS_syslog(LOG_DEBUG, "C-ARES: %s\n", __FUNCTION__);

       EV_DNS_LOGT_STOP(DNS.timeout);
       ev_timer_stop (event_base, &IO->DNS.timeout);

       EV_DNS_LOGT_STOP(unwind_stack);
       ev_idle_stop(event_base, &IO->unwind_stack);
}

Here is the caller graph for this function:

Definition at line 255 of file event_client.c.

{
       IOAddHandler *h;
       int i;

       h = (IOAddHandler*)malloc(sizeof(IOAddHandler));
       h->IO = IO;
       h->EvAttch = evcurl_handle_start;

       pthread_mutex_lock(&EventQueueMutex);
       if (InboundEventQueue == NULL)
       {
              /* shutting down... */
              free(h);
              EVM_syslog(LOG_DEBUG, "EVENT Q exiting.\n");
              pthread_mutex_unlock(&EventQueueMutex);
              return eAbort;
       }

       EVM_syslog(LOG_DEBUG, "EVENT Q\n");
       i = ++evbase_count;
       Put(InboundEventQueue, IKEY(i), h, NULL);
       pthread_mutex_unlock(&EventQueueMutex);

       pthread_mutex_lock(&EventExitQueueMutex);
       if (event_base == NULL) {
              pthread_mutex_unlock(&EventExitQueueMutex);
              return eAbort;
       }
       ev_async_send (event_base, &AddJob);
       pthread_mutex_unlock(&EventExitQueueMutex);

       EVM_syslog(LOG_DEBUG, "EVENT Q Done.\n");
       return eSendReply;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 91 of file event_client.c.

{
       IOAddHandler *h;
       int i;

       h = (IOAddHandler*)malloc(sizeof(IOAddHandler));
       h->IO = IO;
       h->EvAttch = CB;
       ev_cleanup_init(&IO->db_abort_by_shutdown,
                     IO_abort_shutdown_callback);
       IO->db_abort_by_shutdown.data = IO;

       pthread_mutex_lock(&DBEventQueueMutex);
       if (DBInboundEventQueue == NULL)
       {
              /* shutting down... */
              free(h);
              EVM_syslog(LOG_DEBUG, "DBEVENT Q exiting.\n");
              pthread_mutex_unlock(&DBEventQueueMutex);
              return eAbort;
       }
       EVM_syslog(LOG_DEBUG, "DBEVENT Q\n");
       i = ++evdb_count ;
       Put(DBInboundEventQueue, IKEY(i), h, NULL);
       pthread_mutex_unlock(&DBEventQueueMutex);

       pthread_mutex_lock(&DBEventExitQueueMutex);
       if (event_db == NULL)
       {
              pthread_mutex_unlock(&DBEventExitQueueMutex);
              return eAbort;
       }
       ev_async_send (event_db, &DBAddJob);
       pthread_mutex_unlock(&DBEventExitQueueMutex);

       EVM_syslog(LOG_DEBUG, "DBEVENT Q Done.\n");
       return eDBQuery;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 216 of file event_client.c.

{
       IOAddHandler *h;
       int i;

       h = (IOAddHandler*)malloc(sizeof(IOAddHandler));
       h->IO = IO;
       h->EvAttch = CB;
       ev_cleanup_init(&IO->abort_by_shutdown,
                     IO_abort_shutdown_callback);
       IO->abort_by_shutdown.data = IO;

       pthread_mutex_lock(&EventQueueMutex);
       if (InboundEventQueue == NULL)
       {
              free(h);
              /* shutting down... */
              EVM_syslog(LOG_DEBUG, "EVENT Q exiting.\n");
              pthread_mutex_unlock(&EventQueueMutex);
              return eAbort;
       }
       EVM_syslog(LOG_DEBUG, "EVENT Q\n");
       i = ++evbase_count;
       Put(InboundEventQueue, IKEY(i), h, NULL);
       pthread_mutex_unlock(&EventQueueMutex);

       pthread_mutex_lock(&EventExitQueueMutex);
       if (event_base == NULL) {
              pthread_mutex_unlock(&EventExitQueueMutex);
              return eAbort;
       }
       ev_async_send (event_base, &AddJob);
       pthread_mutex_unlock(&EventExitQueueMutex);
       EVM_syslog(LOG_DEBUG, "EVENT Q Done.\n");
       return eSendReply;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void QueueGetHostByName ( AsyncIO IO,
const char *  Hostname,
DNSQueryParts QueryParts,
IO_CallBack  PostDNS 
)

Definition at line 391 of file serv_c-ares-dns.c.

{

       EV_DNS_syslog(LOG_DEBUG, "C-ARES: %s\n", __FUNCTION__);
       IO->DNS.SourcePort = 0;

       IO->DNS.Query = QueryParts;
       IO->DNS.Query->PostDNS = PostDNS;

       InitC_ares_dns(IO);

       ev_timer_init(&IO->DNS.timeout, DNStimeouttrigger_callback, 10, 1);
       EV_DNS_LOGT_INIT(DNS.timeout);
       IO->DNS.timeout.data = IO;
       ares_gethostbyname(IO->DNS.Channel,
                        Hostname,
                        AF_INET6, /* it falls back to ipv4 in doubt... */
                        QueueGetHostByNameDone,
                        IO);
       EV_DNS_LOGT_START(DNS.timeout);
       ev_timer_start(event_base, &IO->DNS.timeout);

}

Here is the call graph for this function:

int QueueQuery ( ns_type  Type,
const char *  name,
AsyncIO IO,
DNSQueryParts QueryParts,
IO_CallBack  PostDNS 
)

Definition at line 418 of file serv_c-ares-dns.c.

{
       int length, family;
       char address_b[sizeof(struct in6_addr)];

       IO->DNS.SourcePort = 0;

       IO->DNS.Query = QueryParts;
       IO->DNS.Query->PostDNS = PostDNS;
       IO->DNS.Start = IO->Now;

       InitC_ares_dns(IO);

       ev_timer_init(&IO->DNS.timeout, DNStimeouttrigger_callback, 10, 1);
       IO->DNS.timeout.data = IO;
       EV_DNS_LOGT_INIT(DNS.timeout);

       switch(Type) {
       case ns_t_a:
              IO->DNS.Query->DNS_CB = ParseAnswerA;
              break;

       case ns_t_aaaa:
              IO->DNS.Query->DNS_CB = ParseAnswerAAAA;
              break;

       case ns_t_mx:
              IO->DNS.Query->DNS_CB = ParseAnswerMX;
              break;

       case ns_t_ns:
              IO->DNS.Query->DNS_CB = ParseAnswerNS;
              break;

       case ns_t_txt:
              IO->DNS.Query->DNS_CB = ParseAnswerTXT;
              break;

       case ns_t_srv:
              IO->DNS.Query->DNS_CB = ParseAnswerSRV;
              break;

       case ns_t_cname:
              IO->DNS.Query->DNS_CB = ParseAnswerCNAME;
              break;

       case ns_t_ptr:


              if (inet_pton(AF_INET, name, &address_b) == 1) {
                     length = sizeof(struct in_addr);
                     family = AF_INET;
              } else if (inet_pton(AF_INET6, name, &address_b) == 1) {
                     length = sizeof(struct in6_addr);
                     family = AF_INET6;
              } else {
                     return -1;
              }

              ares_gethostbyaddr(IO->DNS.Channel,
                               address_b,
                               length,
                               family,
                               HostByAddrCb,
                               IO);
              EV_DNS_LOGT_START(DNS.timeout);
              ev_timer_start(event_base, &IO->DNS.timeout);

              EV_DNS_syslog(LOG_DEBUG, "C-ARES: %s X1\n", __FUNCTION__);

              return 1;

       default:

              EV_DNS_syslog(LOG_DEBUG, "C-ARES: %sX2\n", __FUNCTION__);
              return 0;
       }
       EV_DNS_syslog(LOG_DEBUG, "C-ARES: %s\n", __FUNCTION__);

       ares_query(IO->DNS.Channel, name, ns_c_in, Type, QueryCb, IO);
       EV_DNS_LOGT_START(DNS.timeout);
       ev_timer_start(event_base, &IO->DNS.timeout);
       return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

eNextState ReAttachIO ( AsyncIO IO,
void *  pData,
int  ReadFirst 
)

Definition at line 1006 of file event_client.c.

{
       IO->Data = pData;
       become_session(IO->CitContext);
       ev_cleanup_start(event_base, &IO->abort_by_shutdown);
       if (ReadFirst) {
              IO->NextState = eReadMessage;
       }
       else {
              IO->NextState = eSendReply;
       }
       set_start_callback(event_base, IO, 0);

       return IO->NextState;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SetNextTimeout ( AsyncIO IO,
double  timeout 
)

Definition at line 999 of file event_client.c.

{
       IO->rw_timeout.repeat = timeout;
       ev_timer_again (event_base,  &IO->rw_timeout);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StopClient ( AsyncIO IO)
void StopClientWatchers ( AsyncIO IO,
int  CloseFD 
)

Definition at line 312 of file event_client.c.

{
       ev_timer_stop (event_base, &IO->rw_timeout);
       ev_timer_stop(event_base, &IO->conn_fail);
       ev_idle_stop(event_base, &IO->unwind_stack);
       ev_cleanup_stop(event_base, &IO->abort_by_shutdown);

       ev_io_stop(event_base, &IO->conn_event);
       ev_io_stop(event_base, &IO->send_event);
       ev_io_stop(event_base, &IO->recv_event);

       if (CloseFD && (IO->SendBuf.fd > 0)) {
              close(IO->SendBuf.fd);
              IO->SendBuf.fd = -1;
              IO->RecvBuf.fd = -1;
       }
}

Here is the caller graph for this function:

void StopCurlWatchers ( AsyncIO IO)

Definition at line 330 of file event_client.c.

{
       ev_timer_stop (event_base, &IO->rw_timeout);
       ev_timer_stop(event_base, &IO->conn_fail);
       ev_idle_stop(event_base, &IO->unwind_stack);
       ev_cleanup_stop(event_base, &IO->abort_by_shutdown);

       ev_io_stop(event_base, &IO->conn_event);
       ev_io_stop(event_base, &IO->send_event);
       ev_io_stop(event_base, &IO->recv_event);

       if (IO->SendBuf.fd != 0) {
              close(IO->SendBuf.fd);
       }
       IO->SendBuf.fd = 0;
       IO->RecvBuf.fd = 0;
}

Here is the caller graph for this function:

void StopDBWatchers ( AsyncIO IO)

Definition at line 130 of file event_client.c.

{
       ev_cleanup_stop(event_db, &IO->db_abort_by_shutdown);
       ev_idle_stop(event_db, &IO->db_unwind_stack);
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 60 of file serv_c-ares-dns.c.

Definition at line 63 of file serv_eventclient.c.