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 void *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 FreeURL(&IO->ConnectMe);
206 QueueAnDBOperation(IO);
219 case eTerminateConnection:
221 curl_easy_cleanup(IO->HttpReq.chnd);
222 IO->HttpReq.chnd = NULL;
223 FreeStrBuf(&IO->HttpReq.ReplyData);
224 FreeURL(&IO->ConnectMe);
225 RemoveContext(IO->CitContext);
233 stepmulti(void *data, curl_socket_t fd, int which)
235 int running_handles = 0;
238 msta = curl_multi_socket_action(global.mhnd,
243 CURLM_syslog(LOG_DEBUG, "stepmulti(): calling gotstatus()\n");
246 "error in curl processing events"
247 "on multi handle, fd %d: %s\n",
249 curl_multi_strerror(msta));
251 if (global.nrun != running_handles)
252 gotstatus(running_handles);
256 gottime(struct ev_loop *loop, ev_timer *timeev, int events)
258 CURLM_syslog(LOG_DEBUG, "EVCURL: waking up curl for timeout\n");
259 stepmulti(NULL, CURL_SOCKET_TIMEOUT, 0);
263 got_in(struct ev_loop *loop, ev_io *ioev, int events)
265 CURL_syslog(LOG_DEBUG,
266 "EVCURL: waking up curl for io on fd %d\n",
269 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_IN);
273 got_out(struct ev_loop *loop, ev_io *ioev, int events)
275 CURL_syslog(LOG_DEBUG,
276 "waking up curl for io on fd %d\n",
279 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_OUT);
283 gotdata(void *data, size_t size, size_t nmemb, void *cglobal)
285 AsyncIO *IO = (AsyncIO*) cglobal;
287 SetEVState(IO, eCurlGotData);
288 if (IO->HttpReq.ReplyData == NULL)
290 IO->HttpReq.ReplyData = NewStrBufPlain(NULL, SIZ);
292 IO->Now = ev_now(event_base);
293 return CurlFillStrBuf_callback(data,
296 IO->HttpReq.ReplyData);
300 gotwatchtime(CURLM *multi, long tblock_ms, void *cglobal) {
301 CURL_syslog(LOG_DEBUG, "EVCURL: gotwatchtime called %ld ms\n", tblock_ms);
302 evcurl_global_data *global = cglobal;
303 ev_timer_stop(EV_DEFAULT, &global->timeev);
304 if (tblock_ms < 0 || 14000 < tblock_ms)
306 ev_timer_set(&global->timeev, 0.5e-3 + 1.0e-3 * tblock_ms, 14.0);
307 ev_timer_start(EV_DEFAULT_UC, &global->timeev);
308 curl_multi_perform(global, &global->nrun);
313 gotwatchsock(CURL *easy,
319 evcurl_global_data *global = cglobal;
320 CURLM *mhnd = global->mhnd;
322 AsyncIO *IO = (AsyncIO*) vIO;
327 sta = curl_easy_getinfo(easy, CURLINFO_PRIVATE, &f);
330 "EVCURL: error asking curl for private "
331 "cookie of curl handle: %s\n",
332 curl_easy_strerror(sta));
336 SetEVState(IO, eCurlNewIO);
337 EVCURL_syslog(LOG_DEBUG,
338 "EVCURL: got socket for URL: %s\n",
339 IO->ConnectMe->PlainUrl);
341 if (IO->SendBuf.fd != 0)
343 ev_io_stop(event_base, &IO->recv_event);
344 ev_io_stop(event_base, &IO->send_event);
347 ev_io_init(&IO->recv_event, &got_in, fd, EV_READ);
348 ev_io_init(&IO->send_event, &got_out, fd, EV_WRITE);
349 curl_multi_assign(mhnd, fd, IO);
352 SetEVState(IO, eCurlGotIO);
353 IO->Now = ev_now(event_base);
359 Action = "CURL_POLL_NONE";
361 case CURL_POLL_REMOVE:
362 Action = "CURL_POLL_REMOVE";
365 Action = "CURL_POLL_IN";
368 Action = "CURL_POLL_OUT";
370 case CURL_POLL_INOUT:
371 Action = "CURL_POLL_INOUT";
376 EVCURL_syslog(LOG_DEBUG,
377 "EVCURL: gotwatchsock called fd=%d action=%s[%d]\n",
378 (int)fd, Action, action);
383 EVCURLM_syslog(LOG_DEBUG,
385 "to register this sockwatcker\n");
387 case CURL_POLL_REMOVE:
388 EVCURLM_syslog(LOG_DEBUG,
389 "called last time to unregister "
390 "this sockwatcher\n");
391 ev_io_stop(event_base, &IO->recv_event);
392 ev_io_stop(event_base, &IO->send_event);
395 ev_io_start(event_base, &IO->recv_event);
396 ev_io_stop(event_base, &IO->send_event);
399 ev_io_start(event_base, &IO->send_event);
400 ev_io_stop(event_base, &IO->recv_event);
402 case CURL_POLL_INOUT:
403 ev_io_start(event_base, &IO->send_event);
404 ev_io_start(event_base, &IO->recv_event);
410 void curl_init_connectionpool(void)
414 ev_timer_init(&global.timeev, &gottime, 14.0, 14.0);
415 global.timeev.data = (void *)&global;
417 CURLcode sta = curl_global_init(CURL_GLOBAL_ALL);
422 "error initializing curl library: %s\n",
423 curl_easy_strerror(sta));
427 mhnd = global.mhnd = curl_multi_init();
430 CURLM_syslog(LOG_ERR,
431 "error initializing curl multi handle\n");
435 MOPT(SOCKETFUNCTION, &gotwatchsock);
436 MOPT(SOCKETDATA, (void *)&global);
437 MOPT(TIMERFUNCTION, &gotwatchtime);
438 MOPT(TIMERDATA, (void *)&global);
443 int evcurl_init(AsyncIO *IO)
448 EVCURLM_syslog(LOG_DEBUG, "EVCURL: evcurl_init called ms\n");
449 IO->HttpReq.attached = 0;
450 chnd = IO->HttpReq.chnd = curl_easy_init();
453 EVCURLM_syslog(LOG_ERR, "EVCURL: error initializing curl handle\n");
458 OPT(VERBOSE, (long)1);
463 OPT(FAILONERROR, (long)1);
465 OPT(FOLLOWLOCATION, (long)0);
466 OPT(MAXREDIRS, (long)0);
467 OPT(USERAGENT, CITADEL);
469 OPT(TIMEOUT, (long)1800);
470 OPT(LOW_SPEED_LIMIT, (long)64);
471 OPT(LOW_SPEED_TIME, (long)600);
472 OPT(CONNECTTIMEOUT, (long)600);
473 OPT(PRIVATE, (void *)IO);
475 OPT(FORBID_REUSE, 1);
476 OPT(WRITEFUNCTION, &gotdata);
477 OPT(WRITEDATA, (void *)IO);
478 OPT(ERRORBUFFER, IO->HttpReq.errdesc);
480 if ((!IsEmptyStr(config.c_ip_addr))
481 && (strcmp(config.c_ip_addr, "*"))
482 && (strcmp(config.c_ip_addr, "::"))
483 && (strcmp(config.c_ip_addr, "0.0.0.0"))
486 OPT(INTERFACE, config.c_ip_addr);
489 #ifdef CURLOPT_HTTP_CONTENT_DECODING
490 OPT(HTTP_CONTENT_DECODING, 1);
494 IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers,
495 "Connection: close");
501 static void IOcurl_abort_shutdown_callback(struct ev_loop *loop,
506 AsyncIO *IO = watcher->data;
511 SetEVState(IO, eCurlShutdown);
512 IO->Now = ev_now(event_base);
513 EVCURL_syslog(LOG_DEBUG, "EVENT Curl: %s\n", __FUNCTION__);
515 curl_slist_free_all(IO->HttpReq.headers);
516 msta = curl_multi_remove_handle(global.mhnd, IO->HttpReq.chnd);
519 EVCURL_syslog(LOG_ERR,
520 "EVCURL: warning problem detaching completed handle "
521 "from curl multi: %s\n",
522 curl_multi_strerror(msta));
525 curl_easy_cleanup(IO->HttpReq.chnd);
526 IO->HttpReq.chnd = NULL;
527 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
528 ev_io_stop(event_base, &IO->recv_event);
529 ev_io_stop(event_base, &IO->send_event);
530 assert(IO->ShutdownAbort);
531 IO->ShutdownAbort(IO);
534 evcurl_handle_start(AsyncIO *IO)
540 SetEVState(IO, eCurlStart);
541 chnd = IO->HttpReq.chnd;
542 EVCURL_syslog(LOG_DEBUG,
543 "EVCURL: Loading URL: %s\n", IO->ConnectMe->PlainUrl);
544 OPT(URL, IO->ConnectMe->PlainUrl);
545 if (StrLength(IO->ConnectMe->CurlCreds))
547 OPT(HTTPAUTH, (long)CURLAUTH_BASIC);
548 OPT(USERPWD, ChrPtr(IO->ConnectMe->CurlCreds));
550 if (StrLength(IO->HttpReq.PostData) > 0)
552 OPT(POSTFIELDS, ChrPtr(IO->HttpReq.PostData));
553 OPT(POSTFIELDSIZE, StrLength(IO->HttpReq.PostData));
556 else if ((IO->HttpReq.PlainPostDataLen != 0) &&
557 (IO->HttpReq.PlainPostData != NULL))
559 OPT(POSTFIELDS, IO->HttpReq.PlainPostData);
560 OPT(POSTFIELDSIZE, IO->HttpReq.PlainPostDataLen);
562 OPT(HTTPHEADER, IO->HttpReq.headers);
564 IO->NextState = eConnect;
565 EVCURLM_syslog(LOG_DEBUG, "EVCURL: attaching to curl multi handle\n");
566 msta = curl_multi_add_handle(global.mhnd, IO->HttpReq.chnd);
569 EVCURL_syslog(LOG_ERR,
570 "EVCURL: error attaching to curl multi handle: %s\n",
571 curl_multi_strerror(msta));
574 IO->HttpReq.attached = 1;
575 ev_async_send (event_base, &WakeupCurl);
577 ev_cleanup_init(&IO->abort_by_shutdown,
578 IOcurl_abort_shutdown_callback);
580 ev_cleanup_start(event_base, &IO->abort_by_shutdown);
585 static void WakeupCurlCallback(EV_P_ ev_async *w, int revents)
587 CURLM_syslog(LOG_DEBUG, "waking up curl multi handle\n");
589 curl_multi_perform(&global, CURL_POLL_NONE);
592 static void evcurl_shutdown (void)
594 curl_global_cleanup();
595 curl_multi_cleanup(global.mhnd);
596 CURLM_syslog(LOG_DEBUG, "exiting\n");
598 /*****************************************************************************
599 * libevent integration *
600 *****************************************************************************/
602 * client event queue plus its methods.
603 * this currently is the main loop (which may change in some future?)
605 int evbase_count = 0;
606 pthread_mutex_t EventQueueMutex; /* locks the access to the following vars: */
607 pthread_mutex_t EventExitQueueMutex; /* locks the access to the event queue pointer on exit. */
608 HashList *QueueEvents = NULL;
609 HashList *InboundEventQueue = NULL;
610 HashList *InboundEventQueues[2] = { NULL, NULL };
611 extern void ShutDownCLient(AsyncIO *IO);
614 ev_async ExitEventLoop;
616 static void QueueEventAddCallback(EV_P_ ev_async *w, int revents)
628 /* get the control command... */
629 pthread_mutex_lock(&EventQueueMutex);
631 if (InboundEventQueues[0] == InboundEventQueue) {
632 InboundEventQueue = InboundEventQueues[1];
633 q = InboundEventQueues[0];
636 InboundEventQueue = InboundEventQueues[0];
637 q = InboundEventQueues[1];
639 pthread_mutex_unlock(&EventQueueMutex);
640 Now = ev_now (event_base);
641 It = GetNewHashPos(q, 0);
642 while (GetNextHashPos(q, It, &len, &Key, &v))
646 if (h->IO->ID == 0) {
647 h->IO->ID = EvIDSource++;
650 if (h->IO->StartIO == 0.0)
651 h->IO->StartIO = Now;
653 SetEVState(h->IO, eIOAttach);
655 Ctx = h->IO->CitContext;
659 switch (h->EvAttch(h->IO))
673 case eTerminateConnection:
675 ShutDownCLient(h->IO);
680 DeleteHashContent(&q);
681 EVQ_syslog(LOG_DEBUG, "%s CC[%ld] EVENT Q Add %ld done.", IOSTR, IOID, count);
685 static void EventExitCallback(EV_P_ ev_async *w, int revents)
687 ev_break(event_base, EVBREAK_ALL);
689 EVQM_syslog(LOG_DEBUG, "EVENT Q exiting.\n");
694 void InitEventQueue(void)
696 pthread_mutex_init(&EventQueueMutex, NULL);
697 pthread_mutex_init(&EventExitQueueMutex, NULL);
699 QueueEvents = NewHash(1, Flathash);
700 InboundEventQueues[0] = NewHash(1, Flathash);
701 InboundEventQueues[1] = NewHash(1, Flathash);
702 InboundEventQueue = InboundEventQueues[0];
704 extern void CtdlDestroyEVCleanupHooks(void);
706 extern int EVQShutDown;
707 const char *IOLog = "IO";
709 * this thread operates the select() etc. via libev.
711 void *client_event_thread(void *arg)
713 struct CitContext libev_client_CC;
715 CtdlFillSystemContext(&libev_client_CC, "LibEv Thread");
717 pthread_setspecific(evConKey, IOLog);
719 EVQM_syslog(LOG_DEBUG, "client_event_thread() initializing\n");
721 event_base = ev_default_loop (EVFLAG_AUTO);
722 ev_async_init(&AddJob, QueueEventAddCallback);
723 ev_async_start(event_base, &AddJob);
724 ev_async_init(&ExitEventLoop, EventExitCallback);
725 ev_async_start(event_base, &ExitEventLoop);
726 ev_async_init(&WakeupCurl, WakeupCurlCallback);
727 ev_async_start(event_base, &WakeupCurl);
729 curl_init_connectionpool();
731 ev_run (event_base, 0);
733 EVQM_syslog(LOG_DEBUG, "client_event_thread() exiting\n");
735 ///what todo here? CtdlClearSystemContext();
736 pthread_mutex_lock(&EventExitQueueMutex);
737 ev_loop_destroy (EV_DEFAULT_UC);
739 DeleteHash(&QueueEvents);
740 InboundEventQueue = NULL;
741 DeleteHash(&InboundEventQueues[0]);
742 DeleteHash(&InboundEventQueues[1]);
743 /* citthread_mutex_destroy(&EventQueueMutex); TODO */
746 CtdlDestroyEVCleanupHooks();
748 pthread_mutex_unlock(&EventExitQueueMutex);
753 /*----------------------------------------------------------------------------*/
755 * DB-Queue; does async bdb operations.
756 * has its own set of handlers.
760 pthread_mutex_t DBEventQueueMutex; /* locks the access to the following vars: */
761 pthread_mutex_t DBEventExitQueueMutex; /* locks the access to the db-event queue pointer on exit. */
762 HashList *DBQueueEvents = NULL;
763 HashList *DBInboundEventQueue = NULL;
764 HashList *DBInboundEventQueues[2] = { NULL, NULL };
767 ev_async DBExitEventLoop;
769 extern void ShutDownDBCLient(AsyncIO *IO);
771 static void DBQueueEventAddCallback(EV_P_ ev_async *w, int revents)
783 /* get the control command... */
784 pthread_mutex_lock(&DBEventQueueMutex);
786 if (DBInboundEventQueues[0] == DBInboundEventQueue) {
787 DBInboundEventQueue = DBInboundEventQueues[1];
788 q = DBInboundEventQueues[0];
791 DBInboundEventQueue = DBInboundEventQueues[0];
792 q = DBInboundEventQueues[1];
794 pthread_mutex_unlock(&DBEventQueueMutex);
796 Now = ev_now (event_db);
797 It = GetNewHashPos(q, 0);
798 while (GetNextHashPos(q, It, &len, &Key, &v))
804 h->IO->ID = EvIDSource++;
806 if (h->IO->StartDB == 0.0)
807 h->IO->StartDB = Now;
810 SetEVState(h->IO, eDBAttach);
811 Ctx = h->IO->CitContext;
813 ev_cleanup_start(event_db, &h->IO->db_abort_by_shutdown);
814 rc = h->EvAttch(h->IO);
818 ShutDownDBCLient(h->IO);
824 DeleteHashContent(&q);
825 EVQ_syslog(LOG_DEBUG, "%s CC[%ld] DBEVENT Q Add %ld done.", IOSTR, IOID, count);
829 static void DBEventExitCallback(EV_P_ ev_async *w, int revents)
831 EVQM_syslog(LOG_DEBUG, "DB EVENT Q exiting.\n");
832 ev_break(event_db, EVBREAK_ALL);
837 void DBInitEventQueue(void)
839 pthread_mutex_init(&DBEventQueueMutex, NULL);
840 pthread_mutex_init(&DBEventExitQueueMutex, NULL);
842 DBQueueEvents = NewHash(1, Flathash);
843 DBInboundEventQueues[0] = NewHash(1, Flathash);
844 DBInboundEventQueues[1] = NewHash(1, Flathash);
845 DBInboundEventQueue = DBInboundEventQueues[0];
848 const char *DBLog = "BD";
851 * this thread operates writing to the message database via libev.
853 void *db_event_thread(void *arg)
856 struct CitContext libev_msg_CC;
858 pthread_setspecific(evConKey, DBLog);
860 CtdlFillSystemContext(&libev_msg_CC, "LibEv DB IO Thread");
862 EVQM_syslog(LOG_DEBUG, "dbevent_thread() initializing\n");
864 tmp = event_db = ev_loop_new (EVFLAG_AUTO);
866 ev_async_init(&DBAddJob, DBQueueEventAddCallback);
867 ev_async_start(event_db, &DBAddJob);
868 ev_async_init(&DBExitEventLoop, DBEventExitCallback);
869 ev_async_start(event_db, &DBExitEventLoop);
871 ev_run (event_db, 0);
873 pthread_mutex_lock(&DBEventExitQueueMutex);
876 EVQM_syslog(LOG_INFO, "dbevent_thread() exiting\n");
878 DeleteHash(&DBQueueEvents);
879 DBInboundEventQueue = NULL;
880 DeleteHash(&DBInboundEventQueues[0]);
881 DeleteHash(&DBInboundEventQueues[1]);
883 /* citthread_mutex_destroy(&DBEventQueueMutex); TODO */
885 ev_loop_destroy (tmp);
886 pthread_mutex_unlock(&DBEventExitQueueMutex);
890 void ShutDownEventQueues(void)
892 EVQM_syslog(LOG_DEBUG, "EVENT Qs triggering exits.\n");
894 pthread_mutex_lock(&DBEventQueueMutex);
895 ev_async_send (event_db, &DBExitEventLoop);
896 pthread_mutex_unlock(&DBEventQueueMutex);
898 pthread_mutex_lock(&EventQueueMutex);
899 ev_async_send (EV_DEFAULT_ &ExitEventLoop);
900 pthread_mutex_unlock(&EventQueueMutex);
903 void DebugEventloopEnable(const int n)
907 void DebugEventloopBacktraceEnable(const int n)
909 DebugEventLoopBacktrace = n;
912 void DebugCurlEnable(const int n)
917 const char *WLog = "WX";
918 CTDL_MODULE_INIT(event_client)
922 if (pthread_key_create(&evConKey, NULL) != 0) {
923 syslog(LOG_CRIT, "Can't create TSD key: %s", strerror(errno));
925 pthread_setspecific(evConKey, WLog);
927 CtdlRegisterDebugFlagHook(HKEY("eventloop"), DebugEventloopEnable, &DebugEventLoop);
928 CtdlRegisterDebugFlagHook(HKEY("eventloopbacktrace"), DebugEventloopBacktraceEnable, &DebugEventLoopBacktrace);
929 CtdlRegisterDebugFlagHook(HKEY("curl"), DebugCurlEnable, &DebugCurl);
932 CtdlThreadCreate(client_event_thread);
933 CtdlThreadCreate(db_event_thread);