2 * Copyright (c) 1998-2012 by the citadel.org team
4 * This program is open source software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
28 #include <sys/types.h>
31 #if TIME_WITH_SYS_TIME
32 # include <sys/time.h>
36 # include <sys/time.h>
45 #include <sys/socket.h>
46 #include <netinet/in.h>
48 #include <arpa/inet.h>
49 #include <libcitadel.h>
50 #include <curl/curl.h>
51 #include <curl/multi.h>
54 #include "citserver.h"
57 #include "ctdl_module.h"
59 #include "event_client.h"
60 #include "serv_curl.h"
63 int DebugEventLoop = 0;
64 int DebugEventLoopBacktrace = 0;
66 pthread_key_t evConKey;
69 /*****************************************************************************
70 * libevent / curl integration *
71 *****************************************************************************/
72 #define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (DebugCurl != 0))
74 #define EVCURL_syslog(LEVEL, FORMAT, ...) \
75 DBGLOG (LEVEL) syslog(LEVEL, "EVCURL:%s[%ld]CC[%d] " FORMAT, \
76 IOSTR, IO->ID, CCID, __VA_ARGS__)
78 #define EVCURLM_syslog(LEVEL, FORMAT) \
79 DBGLOG (LEVEL) syslog(LEVEL, "EVCURL:%s[%ld]CC[%d] " FORMAT, \
82 #define CURL_syslog(LEVEL, FORMAT, ...) \
83 DBGLOG (LEVEL) syslog(LEVEL, "CURL: " FORMAT, __VA_ARGS__)
85 #define CURLM_syslog(LEVEL, FORMAT) \
86 DBGLOG (LEVEL) syslog(LEVEL, "CURL: " FORMAT)
90 sta = curl_multi_setopt(mhnd, (CURLMOPT_##s), (v)); \
92 EVQ_syslog(LOG_ERR, "error setting option " \
93 #s " on curl multi handle: %s\n", \
94 curl_easy_strerror(sta)); \
100 typedef struct _evcurl_global_data {
105 } evcurl_global_data;
108 evcurl_global_data global;
110 eNextState QueueAnDBOperation(AsyncIO *IO);
120 CURLM_syslog(LOG_DEBUG,
121 "gotstatus(): about to call curl_multi_info_read\n");
122 while ((msg = curl_multi_info_read(global.mhnd, &nmsg))) {
123 CURL_syslog(LOG_DEBUG,
124 "got curl multi_info message msg=%d\n",
127 if (CURLMSG_DONE == msg->msg) {
129 char *chandle = NULL;
135 chnd = msg->easy_handle;
136 sta = curl_easy_getinfo(chnd,
141 "error asking curl for private"
142 " cookie of curl handle: %s\n",
143 curl_easy_strerror(sta));
146 IO = (AsyncIO *)chandle;
148 EVCURL_syslog(LOG_ERR,
149 "Error, invalid IO context %p\n",
153 SetEVState(IO, eCurlGotStatus);
155 EVCURLM_syslog(LOG_DEBUG, "request complete\n");
157 IO->Now = ev_now(event_base);
159 ev_io_stop(event_base, &IO->recv_event);
160 ev_io_stop(event_base, &IO->send_event);
162 sta = msg->data.result;
164 EVCURL_syslog(LOG_ERR,
165 "error description: %s\n",
166 IO->HttpReq.errdesc);
167 IO->HttpReq.CurlError = curl_easy_strerror(sta);
168 EVCURL_syslog(LOG_ERR,
169 "error performing request: %s\n",
170 IO->HttpReq.CurlError);
171 if (sta == CURLE_OPERATION_TIMEDOUT)
177 sta = curl_easy_getinfo(chnd,
178 CURLINFO_RESPONSE_CODE,
179 &IO->HttpReq.httpcode);
181 EVCURL_syslog(LOG_ERR,
182 "error asking curl for "
183 "response code from request: %s\n",
184 curl_easy_strerror(sta));
185 EVCURL_syslog(LOG_DEBUG,
186 "http response code was %ld\n",
187 (long)IO->HttpReq.httpcode);
190 curl_slist_free_all(IO->HttpReq.headers);
191 msta = curl_multi_remove_handle(global.mhnd, chnd);
193 EVCURL_syslog(LOG_ERR,
194 "warning problem detaching "
195 "completed handle from curl multi: "
197 curl_multi_strerror(msta));
199 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
201 IO->HttpReq.attached = 0;
202 switch(IO->SendDone(IO))
205 curl_easy_cleanup(IO->HttpReq.chnd);
206 IO->HttpReq.chnd = NULL;
207 FreeURL(&IO->ConnectMe);
208 QueueAnDBOperation(IO);
221 case eTerminateConnection:
223 curl_easy_cleanup(IO->HttpReq.chnd);
224 IO->HttpReq.chnd = NULL;
225 FreeStrBuf(&IO->HttpReq.ReplyData);
226 FreeURL(&IO->ConnectMe);
227 RemoveContext(IO->CitContext);
235 stepmulti(void *data, curl_socket_t fd, int which)
237 int running_handles = 0;
240 msta = curl_multi_socket_action(global.mhnd,
245 CURLM_syslog(LOG_DEBUG, "stepmulti(): calling gotstatus()\n");
248 "error in curl processing events"
249 "on multi handle, fd %d: %s\n",
251 curl_multi_strerror(msta));
253 if (global.nrun != running_handles)
254 gotstatus(running_handles);
258 gottime(struct ev_loop *loop, ev_timer *timeev, int events)
260 CURLM_syslog(LOG_DEBUG, "EVCURL: waking up curl for timeout\n");
261 stepmulti(NULL, CURL_SOCKET_TIMEOUT, 0);
265 got_in(struct ev_loop *loop, ev_io *ioev, int events)
267 CURL_syslog(LOG_DEBUG,
268 "EVCURL: waking up curl for io on fd %d\n",
271 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_IN);
275 got_out(struct ev_loop *loop, ev_io *ioev, int events)
277 CURL_syslog(LOG_DEBUG,
278 "waking up curl for io on fd %d\n",
281 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_OUT);
285 gotdata(void *data, size_t size, size_t nmemb, void *cglobal)
287 AsyncIO *IO = (AsyncIO*) cglobal;
289 SetEVState(IO, eCurlGotData);
290 if (IO->HttpReq.ReplyData == NULL)
292 IO->HttpReq.ReplyData = NewStrBufPlain(NULL, SIZ);
294 IO->Now = ev_now(event_base);
295 return CurlFillStrBuf_callback(data,
298 IO->HttpReq.ReplyData);
302 gotwatchtime(CURLM *multi, long tblock_ms, void *cglobal) {
303 CURL_syslog(LOG_DEBUG, "EVCURL: gotwatchtime called %ld ms\n", tblock_ms);
304 evcurl_global_data *global = cglobal;
305 ev_timer_stop(EV_DEFAULT, &global->timeev);
306 if (tblock_ms < 0 || 14000 < tblock_ms)
308 ev_timer_set(&global->timeev, 0.5e-3 + 1.0e-3 * tblock_ms, 14.0);
309 ev_timer_start(EV_DEFAULT_UC, &global->timeev);
310 curl_multi_perform(global, &global->nrun);
315 gotwatchsock(CURL *easy,
321 evcurl_global_data *global = cglobal;
322 CURLM *mhnd = global->mhnd;
324 AsyncIO *IO = (AsyncIO*) vIO;
329 sta = curl_easy_getinfo(easy, CURLINFO_PRIVATE, &f);
332 "EVCURL: error asking curl for private "
333 "cookie of curl handle: %s\n",
334 curl_easy_strerror(sta));
338 SetEVState(IO, eCurlNewIO);
339 EVCURL_syslog(LOG_DEBUG,
340 "EVCURL: got socket for URL: %s\n",
341 IO->ConnectMe->PlainUrl);
343 if (IO->SendBuf.fd != 0)
345 ev_io_stop(event_base, &IO->recv_event);
346 ev_io_stop(event_base, &IO->send_event);
349 ev_io_init(&IO->recv_event, &got_in, fd, EV_READ);
350 ev_io_init(&IO->send_event, &got_out, fd, EV_WRITE);
351 curl_multi_assign(mhnd, fd, IO);
354 SetEVState(IO, eCurlGotIO);
355 IO->Now = ev_now(event_base);
361 Action = "CURL_POLL_NONE";
363 case CURL_POLL_REMOVE:
364 Action = "CURL_POLL_REMOVE";
367 Action = "CURL_POLL_IN";
370 Action = "CURL_POLL_OUT";
372 case CURL_POLL_INOUT:
373 Action = "CURL_POLL_INOUT";
378 EVCURL_syslog(LOG_DEBUG,
379 "EVCURL: gotwatchsock called fd=%d action=%s[%d]\n",
380 (int)fd, Action, action);
385 EVCURLM_syslog(LOG_DEBUG,
387 "to register this sockwatcker\n");
389 case CURL_POLL_REMOVE:
390 EVCURLM_syslog(LOG_DEBUG,
391 "called last time to unregister "
392 "this sockwatcher\n");
393 ev_io_stop(event_base, &IO->recv_event);
394 ev_io_stop(event_base, &IO->send_event);
397 ev_io_start(event_base, &IO->recv_event);
398 ev_io_stop(event_base, &IO->send_event);
401 ev_io_start(event_base, &IO->send_event);
402 ev_io_stop(event_base, &IO->recv_event);
404 case CURL_POLL_INOUT:
405 ev_io_start(event_base, &IO->send_event);
406 ev_io_start(event_base, &IO->recv_event);
412 void curl_init_connectionpool(void)
416 ev_timer_init(&global.timeev, &gottime, 14.0, 14.0);
417 global.timeev.data = (void *)&global;
419 CURLcode sta = curl_global_init(CURL_GLOBAL_ALL);
424 "error initializing curl library: %s\n",
425 curl_easy_strerror(sta));
429 mhnd = global.mhnd = curl_multi_init();
432 CURLM_syslog(LOG_ERR,
433 "error initializing curl multi handle\n");
437 MOPT(SOCKETFUNCTION, &gotwatchsock);
438 MOPT(SOCKETDATA, (void *)&global);
439 MOPT(TIMERFUNCTION, &gotwatchtime);
440 MOPT(TIMERDATA, (void *)&global);
445 int evcurl_init(AsyncIO *IO)
450 EVCURLM_syslog(LOG_DEBUG, "EVCURL: evcurl_init called ms\n");
451 IO->HttpReq.attached = 0;
452 chnd = IO->HttpReq.chnd = curl_easy_init();
455 EVCURLM_syslog(LOG_ERR, "EVCURL: error initializing curl handle\n");
460 OPT(VERBOSE, (long)1);
465 OPT(FAILONERROR, (long)1);
467 OPT(FOLLOWLOCATION, (long)0);
468 OPT(MAXREDIRS, (long)0);
469 OPT(USERAGENT, CITADEL);
471 OPT(TIMEOUT, (long)1800);
472 OPT(LOW_SPEED_LIMIT, (long)64);
473 OPT(LOW_SPEED_TIME, (long)600);
474 OPT(CONNECTTIMEOUT, (long)600);
475 OPT(PRIVATE, (void *)IO);
477 OPT(FORBID_REUSE, 1);
478 OPT(WRITEFUNCTION, &gotdata);
479 OPT(WRITEDATA, (void *)IO);
480 OPT(ERRORBUFFER, IO->HttpReq.errdesc);
482 if ((!IsEmptyStr(config.c_ip_addr))
483 && (strcmp(config.c_ip_addr, "*"))
484 && (strcmp(config.c_ip_addr, "::"))
485 && (strcmp(config.c_ip_addr, "0.0.0.0"))
488 OPT(INTERFACE, config.c_ip_addr);
491 #ifdef CURLOPT_HTTP_CONTENT_DECODING
492 OPT(HTTP_CONTENT_DECODING, 1);
496 IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers,
497 "Connection: close");
503 static void IOcurl_abort_shutdown_callback(struct ev_loop *loop,
508 AsyncIO *IO = watcher->data;
513 SetEVState(IO, eCurlShutdown);
514 IO->Now = ev_now(event_base);
515 EVCURL_syslog(LOG_DEBUG, "EVENT Curl: %s\n", __FUNCTION__);
517 curl_slist_free_all(IO->HttpReq.headers);
518 msta = curl_multi_remove_handle(global.mhnd, IO->HttpReq.chnd);
521 EVCURL_syslog(LOG_ERR,
522 "EVCURL: warning problem detaching completed handle "
523 "from curl multi: %s\n",
524 curl_multi_strerror(msta));
527 curl_easy_cleanup(IO->HttpReq.chnd);
528 IO->HttpReq.chnd = NULL;
529 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
530 ev_io_stop(event_base, &IO->recv_event);
531 ev_io_stop(event_base, &IO->send_event);
532 assert(IO->ShutdownAbort);
533 IO->ShutdownAbort(IO);
536 evcurl_handle_start(AsyncIO *IO)
542 SetEVState(IO, eCurlStart);
543 chnd = IO->HttpReq.chnd;
544 EVCURL_syslog(LOG_DEBUG,
545 "EVCURL: Loading URL: %s\n", IO->ConnectMe->PlainUrl);
546 OPT(URL, IO->ConnectMe->PlainUrl);
547 if (StrLength(IO->ConnectMe->CurlCreds))
549 OPT(HTTPAUTH, (long)CURLAUTH_BASIC);
550 OPT(USERPWD, ChrPtr(IO->ConnectMe->CurlCreds));
552 if (StrLength(IO->HttpReq.PostData) > 0)
554 OPT(POSTFIELDS, ChrPtr(IO->HttpReq.PostData));
555 OPT(POSTFIELDSIZE, StrLength(IO->HttpReq.PostData));
558 else if ((IO->HttpReq.PlainPostDataLen != 0) &&
559 (IO->HttpReq.PlainPostData != NULL))
561 OPT(POSTFIELDS, IO->HttpReq.PlainPostData);
562 OPT(POSTFIELDSIZE, IO->HttpReq.PlainPostDataLen);
564 OPT(HTTPHEADER, IO->HttpReq.headers);
566 IO->NextState = eConnect;
567 EVCURLM_syslog(LOG_DEBUG, "EVCURL: attaching to curl multi handle\n");
568 msta = curl_multi_add_handle(global.mhnd, IO->HttpReq.chnd);
571 EVCURL_syslog(LOG_ERR,
572 "EVCURL: error attaching to curl multi handle: %s\n",
573 curl_multi_strerror(msta));
576 IO->HttpReq.attached = 1;
577 ev_async_send (event_base, &WakeupCurl);
579 ev_cleanup_init(&IO->abort_by_shutdown,
580 IOcurl_abort_shutdown_callback);
582 ev_cleanup_start(event_base, &IO->abort_by_shutdown);
587 static void WakeupCurlCallback(EV_P_ ev_async *w, int revents)
589 CURLM_syslog(LOG_DEBUG, "waking up curl multi handle\n");
591 curl_multi_perform(&global, CURL_POLL_NONE);
594 static void evcurl_shutdown (void)
596 curl_global_cleanup();
597 curl_multi_cleanup(global.mhnd);
598 CURLM_syslog(LOG_DEBUG, "exiting\n");
600 /*****************************************************************************
601 * libevent integration *
602 *****************************************************************************/
604 * client event queue plus its methods.
605 * this currently is the main loop (which may change in some future?)
607 int evbase_count = 0;
608 pthread_mutex_t EventQueueMutex; /* locks the access to the following vars: */
609 pthread_mutex_t EventExitQueueMutex; /* locks the access to the event queue pointer on exit. */
610 HashList *QueueEvents = NULL;
611 HashList *InboundEventQueue = NULL;
612 HashList *InboundEventQueues[2] = { NULL, NULL };
613 extern void ShutDownCLient(AsyncIO *IO);
616 ev_async ExitEventLoop;
618 static void QueueEventAddCallback(EV_P_ ev_async *w, int revents)
630 /* get the control command... */
631 pthread_mutex_lock(&EventQueueMutex);
633 if (InboundEventQueues[0] == InboundEventQueue) {
634 InboundEventQueue = InboundEventQueues[1];
635 q = InboundEventQueues[0];
638 InboundEventQueue = InboundEventQueues[0];
639 q = InboundEventQueues[1];
641 pthread_mutex_unlock(&EventQueueMutex);
642 Now = ev_now (event_base);
643 It = GetNewHashPos(q, 0);
644 while (GetNextHashPos(q, It, &len, &Key, &v))
648 if (h->IO->ID == 0) {
649 h->IO->ID = EvIDSource++;
652 if (h->IO->StartIO == 0.0)
653 h->IO->StartIO = Now;
655 SetEVState(h->IO, eIOAttach);
657 Ctx = h->IO->CitContext;
661 switch (h->EvAttch(h->IO))
675 case eTerminateConnection:
677 ShutDownCLient(h->IO);
682 DeleteHashContent(&q);
683 EVQ_syslog(LOG_DEBUG, "%s CC[%ld] EVENT Q Add %ld done.", IOSTR, IOID, count);
687 static void EventExitCallback(EV_P_ ev_async *w, int revents)
689 ev_break(event_base, EVBREAK_ALL);
691 EVQM_syslog(LOG_DEBUG, "EVENT Q exiting.\n");
696 void InitEventQueue(void)
698 pthread_mutex_init(&EventQueueMutex, NULL);
699 pthread_mutex_init(&EventExitQueueMutex, NULL);
701 QueueEvents = NewHash(1, Flathash);
702 InboundEventQueues[0] = NewHash(1, Flathash);
703 InboundEventQueues[1] = NewHash(1, Flathash);
704 InboundEventQueue = InboundEventQueues[0];
706 extern void CtdlDestroyEVCleanupHooks(void);
708 extern int EVQShutDown;
709 const char *IOLog = "IO";
711 * this thread operates the select() etc. via libev.
713 void *client_event_thread(void *arg)
715 struct CitContext libev_client_CC;
717 CtdlFillSystemContext(&libev_client_CC, "LibEv Thread");
719 pthread_setspecific(evConKey, IOLog);
721 EVQM_syslog(LOG_DEBUG, "client_event_thread() initializing\n");
723 event_base = ev_default_loop (EVFLAG_AUTO);
724 ev_async_init(&AddJob, QueueEventAddCallback);
725 ev_async_start(event_base, &AddJob);
726 ev_async_init(&ExitEventLoop, EventExitCallback);
727 ev_async_start(event_base, &ExitEventLoop);
728 ev_async_init(&WakeupCurl, WakeupCurlCallback);
729 ev_async_start(event_base, &WakeupCurl);
731 curl_init_connectionpool();
733 ev_run (event_base, 0);
735 EVQM_syslog(LOG_DEBUG, "client_event_thread() exiting\n");
737 ///what todo here? CtdlClearSystemContext();
738 pthread_mutex_lock(&EventExitQueueMutex);
739 ev_loop_destroy (EV_DEFAULT_UC);
741 DeleteHash(&QueueEvents);
742 InboundEventQueue = NULL;
743 DeleteHash(&InboundEventQueues[0]);
744 DeleteHash(&InboundEventQueues[1]);
745 /* citthread_mutex_destroy(&EventQueueMutex); TODO */
748 CtdlDestroyEVCleanupHooks();
750 pthread_mutex_unlock(&EventExitQueueMutex);
755 /*----------------------------------------------------------------------------*/
757 * DB-Queue; does async bdb operations.
758 * has its own set of handlers.
762 pthread_mutex_t DBEventQueueMutex; /* locks the access to the following vars: */
763 pthread_mutex_t DBEventExitQueueMutex; /* locks the access to the db-event queue pointer on exit. */
764 HashList *DBQueueEvents = NULL;
765 HashList *DBInboundEventQueue = NULL;
766 HashList *DBInboundEventQueues[2] = { NULL, NULL };
769 ev_async DBExitEventLoop;
771 extern void ShutDownDBCLient(AsyncIO *IO);
773 static void DBQueueEventAddCallback(EV_P_ ev_async *w, int revents)
785 /* get the control command... */
786 pthread_mutex_lock(&DBEventQueueMutex);
788 if (DBInboundEventQueues[0] == DBInboundEventQueue) {
789 DBInboundEventQueue = DBInboundEventQueues[1];
790 q = DBInboundEventQueues[0];
793 DBInboundEventQueue = DBInboundEventQueues[0];
794 q = DBInboundEventQueues[1];
796 pthread_mutex_unlock(&DBEventQueueMutex);
798 Now = ev_now (event_db);
799 It = GetNewHashPos(q, 0);
800 while (GetNextHashPos(q, It, &len, &Key, &v))
806 h->IO->ID = EvIDSource++;
808 if (h->IO->StartDB == 0.0)
809 h->IO->StartDB = Now;
812 SetEVState(h->IO, eDBAttach);
813 Ctx = h->IO->CitContext;
815 ev_cleanup_start(event_db, &h->IO->db_abort_by_shutdown);
816 rc = h->EvAttch(h->IO);
820 ShutDownDBCLient(h->IO);
826 DeleteHashContent(&q);
827 EVQ_syslog(LOG_DEBUG, "%s CC[%ld] DBEVENT Q Add %ld done.", IOSTR, IOID, count);
831 static void DBEventExitCallback(EV_P_ ev_async *w, int revents)
833 EVQM_syslog(LOG_DEBUG, "DB EVENT Q exiting.\n");
834 ev_break(event_db, EVBREAK_ALL);
839 void DBInitEventQueue(void)
841 pthread_mutex_init(&DBEventQueueMutex, NULL);
842 pthread_mutex_init(&DBEventExitQueueMutex, NULL);
844 DBQueueEvents = NewHash(1, Flathash);
845 DBInboundEventQueues[0] = NewHash(1, Flathash);
846 DBInboundEventQueues[1] = NewHash(1, Flathash);
847 DBInboundEventQueue = DBInboundEventQueues[0];
850 const char *DBLog = "BD";
853 * this thread operates writing to the message database via libev.
855 void *db_event_thread(void *arg)
858 struct CitContext libev_msg_CC;
860 pthread_setspecific(evConKey, DBLog);
862 CtdlFillSystemContext(&libev_msg_CC, "LibEv DB IO Thread");
864 EVQM_syslog(LOG_DEBUG, "dbevent_thread() initializing\n");
866 tmp = event_db = ev_loop_new (EVFLAG_AUTO);
868 ev_async_init(&DBAddJob, DBQueueEventAddCallback);
869 ev_async_start(event_db, &DBAddJob);
870 ev_async_init(&DBExitEventLoop, DBEventExitCallback);
871 ev_async_start(event_db, &DBExitEventLoop);
873 ev_run (event_db, 0);
875 pthread_mutex_lock(&DBEventExitQueueMutex);
878 EVQM_syslog(LOG_INFO, "dbevent_thread() exiting\n");
880 DeleteHash(&DBQueueEvents);
881 DBInboundEventQueue = NULL;
882 DeleteHash(&DBInboundEventQueues[0]);
883 DeleteHash(&DBInboundEventQueues[1]);
885 /* citthread_mutex_destroy(&DBEventQueueMutex); TODO */
887 ev_loop_destroy (tmp);
888 pthread_mutex_unlock(&DBEventExitQueueMutex);
892 void ShutDownEventQueues(void)
894 EVQM_syslog(LOG_DEBUG, "EVENT Qs triggering exits.\n");
896 pthread_mutex_lock(&DBEventQueueMutex);
897 ev_async_send (event_db, &DBExitEventLoop);
898 pthread_mutex_unlock(&DBEventQueueMutex);
900 pthread_mutex_lock(&EventQueueMutex);
901 ev_async_send (EV_DEFAULT_ &ExitEventLoop);
902 pthread_mutex_unlock(&EventQueueMutex);
905 void DebugEventloopEnable(const int n)
909 void DebugEventloopBacktraceEnable(const int n)
911 DebugEventLoopBacktrace = n;
914 void DebugCurlEnable(const int n)
919 const char *WLog = "WX";
920 CTDL_MODULE_INIT(event_client)
924 if (pthread_key_create(&evConKey, NULL) != 0) {
925 syslog(LOG_CRIT, "Can't create TSD key: %s", strerror(errno));
927 pthread_setspecific(evConKey, WLog);
929 CtdlRegisterDebugFlagHook(HKEY("eventloop"), DebugEventloopEnable, &DebugEventLoop);
930 CtdlRegisterDebugFlagHook(HKEY("eventloopbacktrace"), DebugEventloopBacktraceEnable, &DebugEventLoopBacktrace);
931 CtdlRegisterDebugFlagHook(HKEY("curl"), DebugCurlEnable, &DebugCurl);
934 CtdlThreadCreate(client_event_thread);
935 CtdlThreadCreate(db_event_thread);