2 * Copyright (c) 1998-2015 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.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
22 #include <sys/types.h>
25 #if TIME_WITH_SYS_TIME
26 # include <sys/time.h>
30 # include <sys/time.h>
39 #include <sys/socket.h>
40 #include <netinet/in.h>
42 #include <arpa/inet.h>
43 #include <libcitadel.h>
44 #include <curl/curl.h>
45 #include <curl/multi.h>
48 #include "citserver.h"
50 #include "ctdl_module.h"
52 #include "event_client.h"
53 #include "serv_curl.h"
56 int DebugEventLoop = 0;
57 int DebugEventLoopBacktrace = 0;
59 pthread_key_t evConKey;
62 /*****************************************************************************
63 * libevent / curl integration *
64 *****************************************************************************/
65 #define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (DebugCurl != 0))
67 #define EVCURL_syslog(LEVEL, FORMAT, ...) \
68 DBGLOG (LEVEL) syslog(LEVEL, "EVCURL:%s[%ld]CC[%d] " FORMAT, \
69 IOSTR, IO->ID, CCID, __VA_ARGS__)
71 #define EVCURLM_syslog(LEVEL, FORMAT) \
72 DBGLOG (LEVEL) syslog(LEVEL, "EVCURL:%s[%ld]CC[%d] " FORMAT, \
75 #define CURL_syslog(LEVEL, FORMAT, ...) \
76 DBGLOG (LEVEL) syslog(LEVEL, "CURL: " FORMAT, __VA_ARGS__)
78 #define CURLM_syslog(LEVEL, FORMAT) \
79 DBGLOG (LEVEL) syslog(LEVEL, "CURL: " FORMAT)
83 sta = curl_multi_setopt(mhnd, (CURLMOPT_##s), (v)); \
85 EVQ_syslog(LOG_ERR, "error setting option " \
86 #s " on curl multi handle: %s\n", \
87 curl_easy_strerror(sta)); \
93 typedef struct _evcurl_global_data {
101 evcurl_global_data global;
103 eNextState QueueAnDBOperation(AsyncIO *IO);
113 CURLM_syslog(LOG_DEBUG,
114 "gotstatus(): about to call curl_multi_info_read\n");
115 while ((msg = curl_multi_info_read(global.mhnd, &nmsg))) {
116 CURL_syslog(LOG_DEBUG,
117 "got curl multi_info message msg=%d\n",
120 if (CURLMSG_DONE == msg->msg) {
122 void *chandle = NULL;
128 chnd = msg->easy_handle;
129 sta = curl_easy_getinfo(chnd,
134 "error asking curl for private"
135 " cookie of curl handle: %s\n",
136 curl_easy_strerror(sta));
139 IO = (AsyncIO *)chandle;
141 EVCURL_syslog(LOG_ERR,
142 "Error, invalid IO context %p\n",
146 SetEVState(IO, eCurlGotStatus);
148 EVCURLM_syslog(LOG_DEBUG, "request complete\n");
150 IO->Now = ev_now(event_base);
152 ev_io_stop(event_base, &IO->recv_event);
153 ev_io_stop(event_base, &IO->send_event);
155 sta = msg->data.result;
157 EVCURL_syslog(LOG_ERR,
158 "error description: %s\n",
159 IO->HttpReq.errdesc);
160 IO->HttpReq.CurlError = curl_easy_strerror(sta);
161 EVCURL_syslog(LOG_ERR,
162 "error performing request: %s\n",
163 IO->HttpReq.CurlError);
164 if (sta == CURLE_OPERATION_TIMEDOUT)
170 sta = curl_easy_getinfo(chnd,
171 CURLINFO_RESPONSE_CODE,
172 &IO->HttpReq.httpcode);
174 EVCURL_syslog(LOG_ERR,
175 "error asking curl for "
176 "response code from request: %s\n",
177 curl_easy_strerror(sta));
178 EVCURL_syslog(LOG_DEBUG,
179 "http response code was %ld\n",
180 (long)IO->HttpReq.httpcode);
183 curl_slist_free_all(IO->HttpReq.headers);
184 msta = curl_multi_remove_handle(global.mhnd, chnd);
186 EVCURL_syslog(LOG_ERR,
187 "warning problem detaching "
188 "completed handle from curl multi: "
190 curl_multi_strerror(msta));
192 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
194 IO->HttpReq.attached = 0;
195 switch(IO->SendDone(IO))
198 FreeURL(&IO->ConnectMe);
199 QueueAnDBOperation(IO);
212 case eTerminateConnection:
214 curl_easy_cleanup(IO->HttpReq.chnd);
215 IO->HttpReq.chnd = NULL;
216 FreeStrBuf(&IO->HttpReq.ReplyData);
217 FreeURL(&IO->ConnectMe);
218 RemoveContext(IO->CitContext);
226 stepmulti(void *data, curl_socket_t fd, int which)
228 int running_handles = 0;
231 msta = curl_multi_socket_action(global.mhnd,
236 CURLM_syslog(LOG_DEBUG, "stepmulti(): calling gotstatus()\n");
239 "error in curl processing events"
240 "on multi handle, fd %d: %s\n",
242 curl_multi_strerror(msta));
244 if (global.nrun != running_handles)
245 gotstatus(running_handles);
249 gottime(struct ev_loop *loop, ev_timer *timeev, int events)
251 CURLM_syslog(LOG_DEBUG, "EVCURL: waking up curl for timeout\n");
252 stepmulti(NULL, CURL_SOCKET_TIMEOUT, 0);
256 got_in(struct ev_loop *loop, ev_io *ioev, int events)
258 CURL_syslog(LOG_DEBUG,
259 "EVCURL: waking up curl for io on fd %d\n",
262 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_IN);
266 got_out(struct ev_loop *loop, ev_io *ioev, int events)
268 CURL_syslog(LOG_DEBUG,
269 "waking up curl for io on fd %d\n",
272 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_OUT);
276 gotdata(void *data, size_t size, size_t nmemb, void *cglobal)
278 AsyncIO *IO = (AsyncIO*) cglobal;
280 SetEVState(IO, eCurlGotData);
281 if (IO->HttpReq.ReplyData == NULL)
283 IO->HttpReq.ReplyData = NewStrBufPlain(NULL, SIZ);
285 IO->Now = ev_now(event_base);
286 return CurlFillStrBuf_callback(data,
289 IO->HttpReq.ReplyData);
293 gotwatchtime(CURLM *multi, long tblock_ms, void *cglobal) {
294 CURL_syslog(LOG_DEBUG, "EVCURL: gotwatchtime called %ld ms\n", tblock_ms);
295 evcurl_global_data *global = cglobal;
296 ev_timer_stop(EV_DEFAULT, &global->timeev);
297 if (tblock_ms < 0 || 14000 < tblock_ms)
299 ev_timer_set(&global->timeev, 0.5e-3 + 1.0e-3 * tblock_ms, 14.0);
300 ev_timer_start(EV_DEFAULT_UC, &global->timeev);
301 curl_multi_perform(global, &global->nrun);
306 gotwatchsock(CURL *easy,
312 evcurl_global_data *global = cglobal;
313 CURLM *mhnd = global->mhnd;
315 AsyncIO *IO = (AsyncIO*) vIO;
320 sta = curl_easy_getinfo(easy, CURLINFO_PRIVATE, &f);
323 "EVCURL: error asking curl for private "
324 "cookie of curl handle: %s\n",
325 curl_easy_strerror(sta));
329 SetEVState(IO, eCurlNewIO);
330 EVCURL_syslog(LOG_DEBUG,
331 "EVCURL: got socket for URL: %s\n",
332 IO->ConnectMe->PlainUrl);
334 if (IO->SendBuf.fd != 0)
336 ev_io_stop(event_base, &IO->recv_event);
337 ev_io_stop(event_base, &IO->send_event);
340 ev_io_init(&IO->recv_event, &got_in, fd, EV_READ);
341 ev_io_init(&IO->send_event, &got_out, fd, EV_WRITE);
342 curl_multi_assign(mhnd, fd, IO);
345 SetEVState(IO, eCurlGotIO);
346 IO->Now = ev_now(event_base);
352 Action = "CURL_POLL_NONE";
354 case CURL_POLL_REMOVE:
355 Action = "CURL_POLL_REMOVE";
358 Action = "CURL_POLL_IN";
361 Action = "CURL_POLL_OUT";
363 case CURL_POLL_INOUT:
364 Action = "CURL_POLL_INOUT";
369 EVCURL_syslog(LOG_DEBUG,
370 "EVCURL: gotwatchsock called fd=%d action=%s[%d]\n",
371 (int)fd, Action, action);
376 EVCURLM_syslog(LOG_DEBUG,
378 "to register this sockwatcker\n");
380 case CURL_POLL_REMOVE:
381 EVCURLM_syslog(LOG_DEBUG,
382 "called last time to unregister "
383 "this sockwatcher\n");
384 ev_io_stop(event_base, &IO->recv_event);
385 ev_io_stop(event_base, &IO->send_event);
388 ev_io_start(event_base, &IO->recv_event);
389 ev_io_stop(event_base, &IO->send_event);
392 ev_io_start(event_base, &IO->send_event);
393 ev_io_stop(event_base, &IO->recv_event);
395 case CURL_POLL_INOUT:
396 ev_io_start(event_base, &IO->send_event);
397 ev_io_start(event_base, &IO->recv_event);
403 void curl_init_connectionpool(void)
407 ev_timer_init(&global.timeev, &gottime, 14.0, 14.0);
408 global.timeev.data = (void *)&global;
410 CURLcode sta = curl_global_init(CURL_GLOBAL_ALL);
415 "error initializing curl library: %s\n",
416 curl_easy_strerror(sta));
420 mhnd = global.mhnd = curl_multi_init();
423 CURLM_syslog(LOG_ERR,
424 "error initializing curl multi handle\n");
428 MOPT(SOCKETFUNCTION, &gotwatchsock);
429 MOPT(SOCKETDATA, (void *)&global);
430 MOPT(TIMERFUNCTION, &gotwatchtime);
431 MOPT(TIMERDATA, (void *)&global);
436 int evcurl_init(AsyncIO *IO)
441 EVCURLM_syslog(LOG_DEBUG, "EVCURL: evcurl_init called ms\n");
442 IO->HttpReq.attached = 0;
443 chnd = IO->HttpReq.chnd = curl_easy_init();
446 EVCURLM_syslog(LOG_ERR, "EVCURL: error initializing curl handle\n");
451 OPT(VERBOSE, (long)1);
456 OPT(FAILONERROR, (long)1);
458 OPT(FOLLOWLOCATION, (long)0);
459 OPT(MAXREDIRS, (long)0);
460 OPT(USERAGENT, CITADEL);
462 OPT(TIMEOUT, (long)1800);
463 OPT(LOW_SPEED_LIMIT, (long)64);
464 OPT(LOW_SPEED_TIME, (long)600);
465 OPT(CONNECTTIMEOUT, (long)600);
466 OPT(PRIVATE, (void *)IO);
468 OPT(FORBID_REUSE, 1);
469 OPT(WRITEFUNCTION, &gotdata);
470 OPT(WRITEDATA, (void *)IO);
471 OPT(ERRORBUFFER, IO->HttpReq.errdesc);
473 if ((!IsEmptyStr(CtdlGetConfigStr("c_ip_addr")))
474 && (strcmp(CtdlGetConfigStr("c_ip_addr"), "*"))
475 && (strcmp(CtdlGetConfigStr("c_ip_addr"), "::"))
476 && (strcmp(CtdlGetConfigStr("c_ip_addr"), "0.0.0.0"))
479 OPT(INTERFACE, CtdlGetConfigStr("c_ip_addr"));
482 #ifdef CURLOPT_HTTP_CONTENT_DECODING
483 OPT(HTTP_CONTENT_DECODING, 1);
487 IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers,
488 "Connection: close");
494 static void IOcurl_abort_shutdown_callback(struct ev_loop *loop,
499 AsyncIO *IO = watcher->data;
504 SetEVState(IO, eCurlShutdown);
505 IO->Now = ev_now(event_base);
506 EVCURL_syslog(LOG_DEBUG, "EVENT Curl: %s\n", __FUNCTION__);
508 curl_slist_free_all(IO->HttpReq.headers);
509 msta = curl_multi_remove_handle(global.mhnd, IO->HttpReq.chnd);
512 EVCURL_syslog(LOG_ERR,
513 "EVCURL: warning problem detaching completed handle "
514 "from curl multi: %s\n",
515 curl_multi_strerror(msta));
518 curl_easy_cleanup(IO->HttpReq.chnd);
519 IO->HttpReq.chnd = NULL;
520 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
521 ev_io_stop(event_base, &IO->recv_event);
522 ev_io_stop(event_base, &IO->send_event);
523 assert(IO->ShutdownAbort);
524 IO->ShutdownAbort(IO);
527 evcurl_handle_start(AsyncIO *IO)
533 SetEVState(IO, eCurlStart);
534 chnd = IO->HttpReq.chnd;
535 EVCURL_syslog(LOG_DEBUG,
536 "EVCURL: Loading URL: %s\n", IO->ConnectMe->PlainUrl);
537 OPT(URL, IO->ConnectMe->PlainUrl);
538 if (StrLength(IO->ConnectMe->CurlCreds))
540 OPT(HTTPAUTH, (long)CURLAUTH_BASIC);
541 OPT(USERPWD, ChrPtr(IO->ConnectMe->CurlCreds));
543 if (StrLength(IO->HttpReq.PostData) > 0)
545 OPT(POSTFIELDS, ChrPtr(IO->HttpReq.PostData));
546 OPT(POSTFIELDSIZE, StrLength(IO->HttpReq.PostData));
549 else if ((IO->HttpReq.PlainPostDataLen != 0) &&
550 (IO->HttpReq.PlainPostData != NULL))
552 OPT(POSTFIELDS, IO->HttpReq.PlainPostData);
553 OPT(POSTFIELDSIZE, IO->HttpReq.PlainPostDataLen);
555 OPT(HTTPHEADER, IO->HttpReq.headers);
557 IO->NextState = eConnect;
558 EVCURLM_syslog(LOG_DEBUG, "EVCURL: attaching to curl multi handle\n");
559 msta = curl_multi_add_handle(global.mhnd, IO->HttpReq.chnd);
562 EVCURL_syslog(LOG_ERR,
563 "EVCURL: error attaching to curl multi handle: %s\n",
564 curl_multi_strerror(msta));
567 IO->HttpReq.attached = 1;
568 ev_async_send (event_base, &WakeupCurl);
570 ev_cleanup_init(&IO->abort_by_shutdown,
571 IOcurl_abort_shutdown_callback);
573 ev_cleanup_start(event_base, &IO->abort_by_shutdown);
578 static void WakeupCurlCallback(EV_P_ ev_async *w, int revents)
580 CURLM_syslog(LOG_DEBUG, "waking up curl multi handle\n");
582 curl_multi_perform(&global, CURL_POLL_NONE);
585 static void evcurl_shutdown (void)
587 curl_global_cleanup();
588 curl_multi_cleanup(global.mhnd);
589 CURLM_syslog(LOG_DEBUG, "exiting\n");
591 /*****************************************************************************
592 * libevent integration *
593 *****************************************************************************/
595 * client event queue plus its methods.
596 * this currently is the main loop (which may change in some future?)
598 int evbase_count = 0;
599 pthread_mutex_t EventQueueMutex; /* locks the access to the following vars: */
600 pthread_mutex_t EventExitQueueMutex; /* locks the access to the event queue pointer on exit. */
601 HashList *QueueEvents = NULL;
602 HashList *InboundEventQueue = NULL;
603 HashList *InboundEventQueues[2] = { NULL, NULL };
604 extern void ShutDownCLient(AsyncIO *IO);
607 ev_async ExitEventLoop;
609 static void QueueEventAddCallback(EV_P_ ev_async *w, int revents)
621 /* get the control command... */
622 pthread_mutex_lock(&EventQueueMutex);
624 if (InboundEventQueues[0] == InboundEventQueue) {
625 InboundEventQueue = InboundEventQueues[1];
626 q = InboundEventQueues[0];
629 InboundEventQueue = InboundEventQueues[0];
630 q = InboundEventQueues[1];
632 pthread_mutex_unlock(&EventQueueMutex);
633 Now = ev_now (event_base);
634 It = GetNewHashPos(q, 0);
635 while (GetNextHashPos(q, It, &len, &Key, &v))
639 if (h->IO->ID == 0) {
640 h->IO->ID = EvIDSource++;
643 if (h->IO->StartIO == 0.0)
644 h->IO->StartIO = Now;
646 SetEVState(h->IO, eIOAttach);
648 Ctx = h->IO->CitContext;
652 switch (h->EvAttch(h->IO))
666 case eTerminateConnection:
668 ShutDownCLient(h->IO);
673 DeleteHashContent(&q);
674 EVQ_syslog(LOG_DEBUG, "%s CC[%ld] EVENT Q Add %ld done.", IOSTR, IOID, count);
678 static void EventExitCallback(EV_P_ ev_async *w, int revents)
680 ev_break(event_base, EVBREAK_ALL);
682 EVQM_syslog(LOG_DEBUG, "EVENT Q exiting.\n");
687 void InitEventQueue(void)
689 pthread_mutex_init(&EventQueueMutex, NULL);
690 pthread_mutex_init(&EventExitQueueMutex, NULL);
692 QueueEvents = NewHash(1, Flathash);
693 InboundEventQueues[0] = NewHash(1, Flathash);
694 InboundEventQueues[1] = NewHash(1, Flathash);
695 InboundEventQueue = InboundEventQueues[0];
697 extern void CtdlDestroyEVCleanupHooks(void);
699 extern int EVQShutDown;
700 const char *IOLog = "IO";
702 * this thread operates the select() etc. via libev.
704 void *client_event_thread(void *arg)
706 struct CitContext libev_client_CC;
708 CtdlFillSystemContext(&libev_client_CC, "LibEv Thread");
710 pthread_setspecific(evConKey, IOLog);
712 EVQM_syslog(LOG_DEBUG, "client_event_thread() initializing\n");
714 event_base = ev_default_loop (EVFLAG_AUTO);
715 ev_async_init(&AddJob, QueueEventAddCallback);
716 ev_async_start(event_base, &AddJob);
717 ev_async_init(&ExitEventLoop, EventExitCallback);
718 ev_async_start(event_base, &ExitEventLoop);
719 ev_async_init(&WakeupCurl, WakeupCurlCallback);
720 ev_async_start(event_base, &WakeupCurl);
722 curl_init_connectionpool();
724 ev_run (event_base, 0);
726 EVQM_syslog(LOG_DEBUG, "client_event_thread() exiting\n");
728 ///what todo here? CtdlClearSystemContext();
729 pthread_mutex_lock(&EventExitQueueMutex);
730 ev_loop_destroy (EV_DEFAULT_UC);
732 DeleteHash(&QueueEvents);
733 InboundEventQueue = NULL;
734 DeleteHash(&InboundEventQueues[0]);
735 DeleteHash(&InboundEventQueues[1]);
736 /* citthread_mutex_destroy(&EventQueueMutex); TODO */
739 CtdlDestroyEVCleanupHooks();
741 pthread_mutex_unlock(&EventExitQueueMutex);
746 /*----------------------------------------------------------------------------*/
748 * DB-Queue; does async bdb operations.
749 * has its own set of handlers.
753 pthread_mutex_t DBEventQueueMutex; /* locks the access to the following vars: */
754 pthread_mutex_t DBEventExitQueueMutex; /* locks the access to the db-event queue pointer on exit. */
755 HashList *DBQueueEvents = NULL;
756 HashList *DBInboundEventQueue = NULL;
757 HashList *DBInboundEventQueues[2] = { NULL, NULL };
760 ev_async DBExitEventLoop;
762 extern void ShutDownDBCLient(AsyncIO *IO);
764 static void DBQueueEventAddCallback(EV_P_ ev_async *w, int revents)
776 /* get the control command... */
777 pthread_mutex_lock(&DBEventQueueMutex);
779 if (DBInboundEventQueues[0] == DBInboundEventQueue) {
780 DBInboundEventQueue = DBInboundEventQueues[1];
781 q = DBInboundEventQueues[0];
784 DBInboundEventQueue = DBInboundEventQueues[0];
785 q = DBInboundEventQueues[1];
787 pthread_mutex_unlock(&DBEventQueueMutex);
789 Now = ev_now (event_db);
790 It = GetNewHashPos(q, 0);
791 while (GetNextHashPos(q, It, &len, &Key, &v))
797 h->IO->ID = EvIDSource++;
799 if (h->IO->StartDB == 0.0)
800 h->IO->StartDB = Now;
803 SetEVState(h->IO, eDBAttach);
804 Ctx = h->IO->CitContext;
806 ev_cleanup_start(event_db, &h->IO->db_abort_by_shutdown);
807 rc = h->EvAttch(h->IO);
811 ShutDownDBCLient(h->IO);
817 DeleteHashContent(&q);
818 EVQ_syslog(LOG_DEBUG, "%s CC[%ld] DBEVENT Q Add %ld done.", IOSTR, IOID, count);
822 static void DBEventExitCallback(EV_P_ ev_async *w, int revents)
824 EVQM_syslog(LOG_DEBUG, "DB EVENT Q exiting.\n");
825 ev_break(event_db, EVBREAK_ALL);
830 void DBInitEventQueue(void)
832 pthread_mutex_init(&DBEventQueueMutex, NULL);
833 pthread_mutex_init(&DBEventExitQueueMutex, NULL);
835 DBQueueEvents = NewHash(1, Flathash);
836 DBInboundEventQueues[0] = NewHash(1, Flathash);
837 DBInboundEventQueues[1] = NewHash(1, Flathash);
838 DBInboundEventQueue = DBInboundEventQueues[0];
841 const char *DBLog = "BD";
844 * this thread operates writing to the message database via libev.
846 void *db_event_thread(void *arg)
849 struct CitContext libev_msg_CC;
851 pthread_setspecific(evConKey, DBLog);
853 CtdlFillSystemContext(&libev_msg_CC, "LibEv DB IO Thread");
855 EVQM_syslog(LOG_DEBUG, "dbevent_thread() initializing\n");
857 tmp = event_db = ev_loop_new (EVFLAG_AUTO);
859 ev_async_init(&DBAddJob, DBQueueEventAddCallback);
860 ev_async_start(event_db, &DBAddJob);
861 ev_async_init(&DBExitEventLoop, DBEventExitCallback);
862 ev_async_start(event_db, &DBExitEventLoop);
864 ev_run (event_db, 0);
866 pthread_mutex_lock(&DBEventExitQueueMutex);
869 EVQM_syslog(LOG_INFO, "dbevent_thread() exiting\n");
871 DeleteHash(&DBQueueEvents);
872 DBInboundEventQueue = NULL;
873 DeleteHash(&DBInboundEventQueues[0]);
874 DeleteHash(&DBInboundEventQueues[1]);
876 /* citthread_mutex_destroy(&DBEventQueueMutex); TODO */
878 ev_loop_destroy (tmp);
879 pthread_mutex_unlock(&DBEventExitQueueMutex);
883 void ShutDownEventQueues(void)
885 EVQM_syslog(LOG_DEBUG, "EVENT Qs triggering exits.\n");
887 pthread_mutex_lock(&DBEventQueueMutex);
888 ev_async_send (event_db, &DBExitEventLoop);
889 pthread_mutex_unlock(&DBEventQueueMutex);
891 pthread_mutex_lock(&EventQueueMutex);
892 ev_async_send (EV_DEFAULT_ &ExitEventLoop);
893 pthread_mutex_unlock(&EventQueueMutex);
896 void DebugEventloopEnable(const int n)
900 void DebugEventloopBacktraceEnable(const int n)
902 DebugEventLoopBacktrace = n;
905 void DebugCurlEnable(const int n)
910 const char *WLog = "WX";
911 CTDL_MODULE_INIT(event_client)
915 if (pthread_key_create(&evConKey, NULL) != 0) {
916 syslog(LOG_CRIT, "Can't create TSD key: %s", strerror(errno));
918 pthread_setspecific(evConKey, WLog);
920 CtdlRegisterDebugFlagHook(HKEY("eventloop"), DebugEventloopEnable, &DebugEventLoop);
921 CtdlRegisterDebugFlagHook(HKEY("eventloopbacktrace"), DebugEventloopBacktraceEnable, &DebugEventLoopBacktrace);
922 CtdlRegisterDebugFlagHook(HKEY("curl"), DebugCurlEnable, &DebugCurl);
925 CtdlThreadCreate(client_event_thread);
926 CtdlThreadCreate(db_event_thread);