X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fevent_client.c;h=d64e95bacc6da8b6ad648a931d3a9931c1fad697;hb=1493fd8ff0de73d30336607b43b1c8113ffcffa2;hp=c633f5357a1e845520eec5d9eee2a8f86439e696;hpb=149b7a41b77a3cc0752fe88090e60ce7dae90a85;p=citadel.git diff --git a/citadel/event_client.c b/citadel/event_client.c index c633f5357..d64e95bac 100644 --- a/citadel/event_client.c +++ b/citadel/event_client.c @@ -9,60 +9,65 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ - #include "sysdep.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif -#include -#include +#include #include -#include +#include +#include #include #include #include -#include #if HAVE_BACKTRACE #include #endif #include -#include "citadel.h" -#include "server.h" -#include "citserver.h" -#include "support.h" -#include "config.h" -#include "control.h" -#include "user_ops.h" -#include "database.h" -#include "msgbase.h" -#include "internet_addressing.h" -#include "genstamp.h" -#include "domain.h" -#include "clientsocket.h" -#include "locate_host.h" -#include "citadel_dirs.h" -#include "event_client.h" #include "ctdl_module.h" +#include "event_client.h" + +ConstStr IOStates[] = { + {HKEY("DB Queue")}, + {HKEY("DB Q Next")}, + {HKEY("DB Attach")}, + {HKEY("DB Next")}, + {HKEY("DB Stop")}, + {HKEY("DB Exit")}, + {HKEY("DB Terminate")}, + {HKEY("IO Queue")}, + {HKEY("IO Attach")}, + {HKEY("IO Connect Socket")}, + {HKEY("IO Abort")}, + {HKEY("IO Timeout")}, + {HKEY("IO ConnFail")}, + {HKEY("IO ConnFail Now")}, + {HKEY("IO Conn Now")}, + {HKEY("IO Conn Wait")}, + {HKEY("Curl Q")}, + {HKEY("Curl Start")}, + {HKEY("Curl Shotdown")}, + {HKEY("Curl More IO")}, + {HKEY("Curl Got IO")}, + {HKEY("Curl Got Data")}, + {HKEY("Curl Got Status")}, + {HKEY("C-Ares Start")}, + {HKEY("C-Ares IO Done")}, + {HKEY("C-Ares Finished")}, + {HKEY("C-Ares exit")}, + {HKEY("Killing")}, + {HKEY("Exit")} +}; + +void SetEVState(AsyncIO *IO, eIOState State) +{ + + CitContext* CCC = IO->CitContext; + if (CCC != NULL) + memcpy(CCC->lastcmdname, IOStates[State].Key, IOStates[State].len + 1); + +} + static void IO_Timeout_callback(struct ev_loop *loop, ev_timer *watcher, int revents); static void IO_abort_shutdown_callback(struct ev_loop *loop, @@ -86,6 +91,7 @@ eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB) IOAddHandler *h; int i; + SetEVState(IO, eDBQ); h = (IOAddHandler*)malloc(sizeof(IOAddHandler)); h->IO = IO; h->EvAttch = CB; @@ -122,6 +128,7 @@ eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB) void StopDBWatchers(AsyncIO *IO) { + SetEVState(IO, eDBStop); ev_cleanup_stop(event_db, &IO->db_abort_by_shutdown); ev_idle_stop(event_db, &IO->db_unwind_stack); } @@ -131,6 +138,7 @@ void ShutDownDBCLient(AsyncIO *IO) CitContext *Ctx =IO->CitContext; become_session(Ctx); + SetEVState(IO, eDBTerm); EVM_syslog(LOG_DEBUG, "DBEVENT Terminating.\n"); StopDBWatchers(IO); @@ -142,6 +150,8 @@ void DB_PerformNext(struct ev_loop *loop, ev_idle *watcher, int revents) { AsyncIO *IO = watcher->data; + + SetEVState(IO, eDBNext); IO->Now = ev_now(event_db); EV_syslog(LOG_DEBUG, "%s()", __FUNCTION__); become_session(IO->CitContext); @@ -175,6 +185,7 @@ DB_PerformNext(struct ev_loop *loop, ev_idle *watcher, int revents) eNextState NextDBOperation(AsyncIO *IO, IO_CallBack CB) { + SetEVState(IO, eQDBNext); IO->NextDBOperation = CB; ev_idle_init(&IO->db_unwind_stack, DB_PerformNext); @@ -199,6 +210,8 @@ static void IO_abort_shutdown_callback(struct ev_loop *loop, int revents) { AsyncIO *IO = watcher->data; + + SetEVState(IO, eIOAbort); EV_syslog(LOG_DEBUG, "EVENT Q: %s\n", __FUNCTION__); IO->Now = ev_now(event_base); assert(IO->ShutdownAbort); @@ -211,6 +224,7 @@ eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB) IOAddHandler *h; int i; + SetEVState(IO, eIOQ); h = (IOAddHandler*)malloc(sizeof(IOAddHandler)); h->IO = IO; h->EvAttch = CB; @@ -243,6 +257,17 @@ eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB) return eSendReply; } +eNextState EventQueueDBOperation(AsyncIO *IO, IO_CallBack CB) +{ + StopClientWatchers(IO, 0); + return QueueDBOperation(IO, CB); +} +eNextState DBQueueEventContext(AsyncIO *IO, IO_CallBack CB) +{ + StopDBWatchers(IO); + return QueueEventContext(IO, CB); +} + extern eNextState evcurl_handle_start(AsyncIO *IO); eNextState QueueCurlContext(AsyncIO *IO) @@ -250,6 +275,7 @@ eNextState QueueCurlContext(AsyncIO *IO) IOAddHandler *h; int i; + SetEVState(IO, eCurlQ); h = (IOAddHandler*)malloc(sizeof(IOAddHandler)); h->IO = IO; h->EvAttch = evcurl_handle_start; @@ -281,6 +307,13 @@ eNextState QueueCurlContext(AsyncIO *IO) return eSendReply; } +eNextState CurlQueueDBOperation(AsyncIO *IO, IO_CallBack CB) +{ + StopCurlWatchers(IO); + return QueueDBOperation(IO, CB); +} + + void DestructCAres(AsyncIO *IO); void FreeAsyncIOContents(AsyncIO *IO) { @@ -305,6 +338,8 @@ void FreeAsyncIOContents(AsyncIO *IO) void StopClientWatchers(AsyncIO *IO, int CloseFD) { + EVM_syslog(LOG_DEBUG, "EVENT StopClientWatchers"); + ev_timer_stop (event_base, &IO->rw_timeout); ev_timer_stop(event_base, &IO->conn_fail); ev_idle_stop(event_base, &IO->unwind_stack); @@ -323,6 +358,8 @@ void StopClientWatchers(AsyncIO *IO, int CloseFD) void StopCurlWatchers(AsyncIO *IO) { + EVM_syslog(LOG_DEBUG, "EVENT StopCurlWatchers \n"); + ev_timer_stop (event_base, &IO->rw_timeout); ev_timer_stop(event_base, &IO->conn_fail); ev_idle_stop(event_base, &IO->unwind_stack); @@ -332,6 +369,9 @@ void StopCurlWatchers(AsyncIO *IO) ev_io_stop(event_base, &IO->send_event); ev_io_stop(event_base, &IO->recv_event); + curl_easy_cleanup(IO->HttpReq.chnd); + IO->HttpReq.chnd = NULL; + if (IO->SendBuf.fd != 0) { close(IO->SendBuf.fd); } @@ -342,6 +382,8 @@ void StopCurlWatchers(AsyncIO *IO) void ShutDownCLient(AsyncIO *IO) { CitContext *Ctx =IO->CitContext; + + SetEVState(IO, eExit); become_session(Ctx); EVM_syslog(LOG_DEBUG, "EVENT Terminating \n"); @@ -642,6 +684,7 @@ IO_Timeout_callback(struct ev_loop *loop, ev_timer *watcher, int revents) { AsyncIO *IO = watcher->data; + SetEVState(IO, eIOTimeout); IO->Now = ev_now(event_base); ev_timer_stop (event_base, &IO->rw_timeout); become_session(IO->CitContext); @@ -670,6 +713,7 @@ IO_connfail_callback(struct ev_loop *loop, ev_timer *watcher, int revents) { AsyncIO *IO = watcher->data; + SetEVState(IO, eIOConnfail); IO->Now = ev_now(event_base); ev_timer_stop (event_base, &IO->conn_fail); @@ -702,6 +746,7 @@ IO_connfailimmediate_callback(struct ev_loop *loop, { AsyncIO *IO = watcher->data; + SetEVState(IO, eIOConnfailNow); IO->Now = ev_now(event_base); ev_idle_stop (event_base, &IO->conn_fail_immediate); @@ -731,6 +776,7 @@ IO_connestd_callback(struct ev_loop *loop, ev_io *watcher, int revents) socklen_t lon = sizeof(so_err); int err; + SetEVState(IO, eIOConnNow); IO->Now = ev_now(event_base); EVM_syslog(LOG_DEBUG, "connect() succeeded.\n"); @@ -844,6 +890,8 @@ void IO_postdns_callback(struct ev_loop *loop, ev_idle *watcher, int revents) { AsyncIO *IO = watcher->data; + + SetEVState(IO, eCaresFinished); IO->Now = ev_now(event_base); EV_syslog(LOG_DEBUG, "event: %s\n", __FUNCTION__); become_session(IO->CitContext); @@ -874,6 +922,7 @@ eNextState EvConnectSock(AsyncIO *IO, int fdflags; int rc = -1; + SetEVState(IO, eIOConnectSock); become_session(IO->CitContext); if (ReadFirst) { @@ -976,11 +1025,13 @@ eNextState EvConnectSock(AsyncIO *IO, } if (rc >= 0){ + SetEVState(IO, eIOConnNow); EV_syslog(LOG_DEBUG, "connect() = %d immediate success.\n", IO->SendBuf.fd); set_start_callback(event_base, IO, 0); return IO->NextState; } else if (errno == EINPROGRESS) { + SetEVState(IO, eIOConnWait); EV_syslog(LOG_DEBUG, "connect() = %d have to wait now.\n", IO->SendBuf.fd); ev_io_init(&IO->conn_event, @@ -995,6 +1046,7 @@ eNextState EvConnectSock(AsyncIO *IO, return IO->NextState; } else { + SetEVState(IO, eIOConnfail); ev_idle_init(&IO->conn_fail_immediate, IO_connfailimmediate_callback); IO->conn_fail_immediate.data = IO; @@ -1024,6 +1076,7 @@ eNextState ReAttachIO(AsyncIO *IO, void *pData, int ReadFirst) { + SetEVState(IO, eIOAttach); IO->Data = pData; become_session(IO->CitContext); ev_cleanup_start(event_base, &IO->abort_by_shutdown); @@ -1115,10 +1168,13 @@ typedef struct KillOtherSessionContext { eNextState KillTerminate(AsyncIO *IO) { + long id; KillOtherSessionContext *Ctx = (KillOtherSessionContext*)IO->Data; EV_syslog(LOG_DEBUG, "%s Exit\n", __FUNCTION__); + id = IO->ID; FreeAsyncIOContents(IO); memset(Ctx, 0, sizeof(KillOtherSessionContext)); + IO->ID = id; /* just for the case we want to analyze it in a coredump */ free(Ctx); return eAbort; @@ -1133,6 +1189,8 @@ eNextState KillOtherContextNow(AsyncIO *IO) { KillOtherSessionContext *Ctx = IO->Data; + SetEVState(IO, eKill); + if (Ctx->OtherOne->ShutdownAbort != NULL) Ctx->OtherOne->ShutdownAbort(Ctx->OtherOne); return eTerminateConnection;