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->CitContext->lastcmd = 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 IO->HttpReq.headers = NULL;
192 msta = curl_multi_remove_handle(global.mhnd, chnd);
194 EVCURL_syslog(LOG_ERR,
195 "warning problem detaching "
196 "completed handle from curl multi: "
198 curl_multi_strerror(msta));
200 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
202 IO->HttpReq.attached = 0;
203 switch(IO->SendDone(IO))
206 FreeURL(&IO->ConnectMe);
207 QueueAnDBOperation(IO);
220 case eTerminateConnection:
222 curl_easy_cleanup(IO->HttpReq.chnd);
223 IO->HttpReq.chnd = NULL;
224 FreeStrBuf(&IO->HttpReq.ReplyData);
225 FreeURL(&IO->ConnectMe);
226 RemoveContext(IO->CitContext);
234 stepmulti(void *data, curl_socket_t fd, int which)
236 int running_handles = 0;
239 msta = curl_multi_socket_action(global.mhnd,
244 CURLM_syslog(LOG_DEBUG, "stepmulti(): calling gotstatus()\n");
247 "error in curl processing events"
248 "on multi handle, fd %d: %s\n",
250 curl_multi_strerror(msta));
252 if (global.nrun != running_handles)
253 gotstatus(running_handles);
257 gottime(struct ev_loop *loop, ev_timer *timeev, int events)
259 CURLM_syslog(LOG_DEBUG, "EVCURL: waking up curl for timeout\n");
260 stepmulti(NULL, CURL_SOCKET_TIMEOUT, 0);
264 got_in(struct ev_loop *loop, ev_io *ioev, int events)
266 CURL_syslog(LOG_DEBUG,
267 "EVCURL: waking up curl for io on fd %d\n",
270 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_IN);
274 got_out(struct ev_loop *loop, ev_io *ioev, int events)
276 CURL_syslog(LOG_DEBUG,
277 "waking up curl for io on fd %d\n",
280 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_OUT);
284 gotdata(void *data, size_t size, size_t nmemb, void *cglobal)
286 AsyncIO *IO = (AsyncIO*) cglobal;
288 SetEVState(IO, eCurlGotData);
289 if (IO->HttpReq.ReplyData == NULL)
291 IO->HttpReq.ReplyData = NewStrBufPlain(NULL, SIZ);
293 IO->CitContext->lastcmd = IO->Now = ev_now(event_base);
294 return CurlFillStrBuf_callback(data,
297 IO->HttpReq.ReplyData);
301 gotwatchtime(CURLM *multi, long tblock_ms, void *cglobal) {
302 CURL_syslog(LOG_DEBUG, "EVCURL: gotwatchtime called %ld ms\n", tblock_ms);
303 evcurl_global_data *global = cglobal;
304 ev_timer_stop(EV_DEFAULT, &global->timeev);
305 if (tblock_ms < 0 || 14000 < tblock_ms)
307 ev_timer_set(&global->timeev, 0.5e-3 + 1.0e-3 * tblock_ms, 14.0);
308 ev_timer_start(EV_DEFAULT_UC, &global->timeev);
309 curl_multi_perform(global, &global->nrun);
314 gotwatchsock(CURL *easy,
320 evcurl_global_data *global = cglobal;
321 CURLM *mhnd = global->mhnd;
323 AsyncIO *IO = (AsyncIO*) vIO;
328 sta = curl_easy_getinfo(easy, CURLINFO_PRIVATE, &f);
331 "EVCURL: error asking curl for private "
332 "cookie of curl handle: %s\n",
333 curl_easy_strerror(sta));
337 SetEVState(IO, eCurlNewIO);
338 EVCURL_syslog(LOG_DEBUG,
339 "EVCURL: got socket for URL: %s\n",
340 IO->ConnectMe->PlainUrl);
342 if (IO->SendBuf.fd != 0)
344 ev_io_stop(event_base, &IO->recv_event);
345 ev_io_stop(event_base, &IO->send_event);
348 ev_io_init(&IO->recv_event, &got_in, fd, EV_READ);
349 ev_io_init(&IO->send_event, &got_out, fd, EV_WRITE);
350 curl_multi_assign(mhnd, fd, IO);
353 SetEVState(IO, eCurlGotIO);
354 IO->CitContext->lastcmd = IO->Now = ev_now(event_base);
360 Action = "CURL_POLL_NONE";
362 case CURL_POLL_REMOVE:
363 Action = "CURL_POLL_REMOVE";
366 Action = "CURL_POLL_IN";
369 Action = "CURL_POLL_OUT";
371 case CURL_POLL_INOUT:
372 Action = "CURL_POLL_INOUT";
377 EVCURL_syslog(LOG_DEBUG,
378 "EVCURL: gotwatchsock called fd=%d action=%s[%d]\n",
379 (int)fd, Action, action);
384 EVCURLM_syslog(LOG_DEBUG,
386 "to register this sockwatcker\n");
388 case CURL_POLL_REMOVE:
389 EVCURLM_syslog(LOG_DEBUG,
390 "called last time to unregister "
391 "this sockwatcher\n");
392 ev_io_stop(event_base, &IO->recv_event);
393 ev_io_stop(event_base, &IO->send_event);
396 ev_io_start(event_base, &IO->recv_event);
397 ev_io_stop(event_base, &IO->send_event);
400 ev_io_start(event_base, &IO->send_event);
401 ev_io_stop(event_base, &IO->recv_event);
403 case CURL_POLL_INOUT:
404 ev_io_start(event_base, &IO->send_event);
405 ev_io_start(event_base, &IO->recv_event);
411 void curl_init_connectionpool(void)
415 ev_timer_init(&global.timeev, &gottime, 14.0, 14.0);
416 global.timeev.data = (void *)&global;
418 CURLcode sta = curl_global_init(CURL_GLOBAL_ALL);
423 "error initializing curl library: %s\n",
424 curl_easy_strerror(sta));
428 mhnd = global.mhnd = curl_multi_init();
431 CURLM_syslog(LOG_ERR,
432 "error initializing curl multi handle\n");
436 MOPT(SOCKETFUNCTION, &gotwatchsock);
437 MOPT(SOCKETDATA, (void *)&global);
438 MOPT(TIMERFUNCTION, &gotwatchtime);
439 MOPT(TIMERDATA, (void *)&global);
444 int evcurl_init(AsyncIO *IO)
449 EVCURLM_syslog(LOG_DEBUG, "EVCURL: evcurl_init called ms\n");
450 IO->HttpReq.attached = 0;
451 chnd = IO->HttpReq.chnd = curl_easy_init();
454 EVCURLM_syslog(LOG_ERR, "EVCURL: error initializing curl handle\n");
459 OPT(VERBOSE, (long)1);
464 OPT(FAILONERROR, (long)1);
466 OPT(FOLLOWLOCATION, (long)0);
467 OPT(MAXREDIRS, (long)0);
468 OPT(USERAGENT, CITADEL);
470 OPT(TIMEOUT, (long)1800);
471 OPT(LOW_SPEED_LIMIT, (long)64);
472 OPT(LOW_SPEED_TIME, (long)600);
473 OPT(CONNECTTIMEOUT, (long)600);
474 OPT(PRIVATE, (void *)IO);
476 OPT(FORBID_REUSE, 1);
477 OPT(WRITEFUNCTION, &gotdata);
478 OPT(WRITEDATA, (void *)IO);
479 OPT(ERRORBUFFER, IO->HttpReq.errdesc);
481 if ((!IsEmptyStr(config.c_ip_addr))
482 && (strcmp(config.c_ip_addr, "*"))
483 && (strcmp(config.c_ip_addr, "::"))
484 && (strcmp(config.c_ip_addr, "0.0.0.0"))
487 OPT(INTERFACE, config.c_ip_addr);
490 #ifdef CURLOPT_HTTP_CONTENT_DECODING
491 OPT(HTTP_CONTENT_DECODING, 1);
495 IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers,
496 "Connection: close");
502 static void IOcurl_abort_shutdown_callback(struct ev_loop *loop,
507 AsyncIO *IO = watcher->data;
512 SetEVState(IO, eCurlShutdown);
513 IO->CitContext->lastcmd = IO->Now = ev_now(event_base);
514 EVCURL_syslog(LOG_DEBUG, "EVENT Curl: %s\n", __FUNCTION__);
516 curl_slist_free_all(IO->HttpReq.headers);
517 IO->HttpReq.headers = NULL;
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);
537 evcurl_handle_start(AsyncIO *IO)
543 SetEVState(IO, eCurlStart);
544 chnd = IO->HttpReq.chnd;
545 EVCURL_syslog(LOG_DEBUG,
546 "EVCURL: Loading URL: %s\n", IO->ConnectMe->PlainUrl);
547 OPT(URL, IO->ConnectMe->PlainUrl);
548 if (StrLength(IO->ConnectMe->CurlCreds))
550 OPT(HTTPAUTH, (long)CURLAUTH_BASIC);
551 OPT(USERPWD, ChrPtr(IO->ConnectMe->CurlCreds));
553 if (StrLength(IO->HttpReq.PostData) > 0)
555 OPT(POSTFIELDS, ChrPtr(IO->HttpReq.PostData));
556 OPT(POSTFIELDSIZE, StrLength(IO->HttpReq.PostData));
559 else if ((IO->HttpReq.PlainPostDataLen != 0) &&
560 (IO->HttpReq.PlainPostData != NULL))
562 OPT(POSTFIELDS, IO->HttpReq.PlainPostData);
563 OPT(POSTFIELDSIZE, IO->HttpReq.PlainPostDataLen);
565 OPT(HTTPHEADER, IO->HttpReq.headers);
567 IO->NextState = eConnect;
568 EVCURLM_syslog(LOG_DEBUG, "EVCURL: attaching to curl multi handle\n");
569 msta = curl_multi_add_handle(global.mhnd, IO->HttpReq.chnd);
572 EVCURL_syslog(LOG_ERR,
573 "EVCURL: error attaching to curl multi handle: %s\n",
574 curl_multi_strerror(msta));
577 IO->HttpReq.attached = 1;
578 ev_async_send (event_base, &WakeupCurl);
580 ev_cleanup_init(&IO->abort_by_shutdown,
581 IOcurl_abort_shutdown_callback);
583 ev_cleanup_start(event_base, &IO->abort_by_shutdown);
588 static void WakeupCurlCallback(EV_P_ ev_async *w, int revents)
590 CURLM_syslog(LOG_DEBUG, "waking up curl multi handle\n");
592 curl_multi_perform(&global, CURL_POLL_NONE);
595 static void evcurl_shutdown (void)
597 curl_global_cleanup();
598 curl_multi_cleanup(global.mhnd);
599 CURLM_syslog(LOG_DEBUG, "exiting\n");
601 /*****************************************************************************
602 * libevent integration *
603 *****************************************************************************/
605 * client event queue plus its methods.
606 * this currently is the main loop (which may change in some future?)
608 int evbase_count = 0;
609 pthread_mutex_t EventQueueMutex; /* locks the access to the following vars: */
610 pthread_mutex_t EventExitQueueMutex; /* locks the access to the event queue pointer on exit. */
611 HashList *QueueEvents = NULL;
612 HashList *InboundEventQueue = NULL;
613 HashList *InboundEventQueues[2] = { NULL, NULL };
614 extern void ShutDownCLient(AsyncIO *IO);
617 ev_async ExitEventLoop;
619 static void QueueEventAddCallback(EV_P_ ev_async *w, int revents)
631 /* get the control command... */
632 pthread_mutex_lock(&EventQueueMutex);
634 if (InboundEventQueues[0] == InboundEventQueue) {
635 InboundEventQueue = InboundEventQueues[1];
636 q = InboundEventQueues[0];
639 InboundEventQueue = InboundEventQueues[0];
640 q = InboundEventQueues[1];
642 pthread_mutex_unlock(&EventQueueMutex);
643 Now = ev_now (event_base);
644 It = GetNewHashPos(q, 0);
645 while (GetNextHashPos(q, It, &len, &Key, &v))
649 if (h->IO->ID == 0) {
650 h->IO->ID = EvIDSource++;
653 if (h->IO->StartIO == 0.0)
654 h->IO->StartIO = Now;
656 SetEVState(h->IO, eIOAttach);
658 Ctx = h->IO->CitContext;
661 h->IO->CitContext->lastcmd = h->IO->Now = Now;
662 switch (h->EvAttch(h->IO))
676 case eTerminateConnection:
678 ShutDownCLient(h->IO);
683 DeleteHashContent(&q);
684 EVQ_syslog(LOG_DEBUG, "%s CC[%ld] EVENT Q Add %ld done.", IOSTR, IOID, count);
688 static void EventExitCallback(EV_P_ ev_async *w, int revents)
690 ev_break(event_base, EVBREAK_ALL);
692 EVQM_syslog(LOG_DEBUG, "EVENT Q exiting.\n");
697 void InitEventQueue(void)
699 pthread_mutex_init(&EventQueueMutex, NULL);
700 pthread_mutex_init(&EventExitQueueMutex, NULL);
702 QueueEvents = NewHash(1, Flathash);
703 InboundEventQueues[0] = NewHash(1, Flathash);
704 InboundEventQueues[1] = NewHash(1, Flathash);
705 InboundEventQueue = InboundEventQueues[0];
707 extern void CtdlDestroyEVCleanupHooks(void);
709 extern int EVQShutDown;
710 const char *IOLog = "IO";
712 * this thread operates the select() etc. via libev.
714 void *client_event_thread(void *arg)
716 struct CitContext libev_client_CC;
718 CtdlFillSystemContext(&libev_client_CC, "LibEv Thread");
720 pthread_setspecific(evConKey, IOLog);
722 EVQM_syslog(LOG_DEBUG, "client_event_thread() initializing\n");
724 event_base = ev_default_loop (EVFLAG_AUTO);
725 ev_async_init(&AddJob, QueueEventAddCallback);
726 ev_async_start(event_base, &AddJob);
727 ev_async_init(&ExitEventLoop, EventExitCallback);
728 ev_async_start(event_base, &ExitEventLoop);
729 ev_async_init(&WakeupCurl, WakeupCurlCallback);
730 ev_async_start(event_base, &WakeupCurl);
732 curl_init_connectionpool();
734 ev_run (event_base, 0);
736 EVQM_syslog(LOG_DEBUG, "client_event_thread() exiting\n");
738 ///what todo here? CtdlClearSystemContext();
739 pthread_mutex_lock(&EventExitQueueMutex);
740 ev_loop_destroy (EV_DEFAULT_UC);
742 DeleteHash(&QueueEvents);
743 InboundEventQueue = NULL;
744 DeleteHash(&InboundEventQueues[0]);
745 DeleteHash(&InboundEventQueues[1]);
746 /* citthread_mutex_destroy(&EventQueueMutex); TODO */
749 CtdlDestroyEVCleanupHooks();
751 pthread_mutex_unlock(&EventExitQueueMutex);
756 /*----------------------------------------------------------------------------*/
758 * DB-Queue; does async bdb operations.
759 * has its own set of handlers.
763 pthread_mutex_t DBEventQueueMutex; /* locks the access to the following vars: */
764 pthread_mutex_t DBEventExitQueueMutex; /* locks the access to the db-event queue pointer on exit. */
765 HashList *DBQueueEvents = NULL;
766 HashList *DBInboundEventQueue = NULL;
767 HashList *DBInboundEventQueues[2] = { NULL, NULL };
770 ev_async DBExitEventLoop;
772 extern void ShutDownDBCLient(AsyncIO *IO);
774 static void DBQueueEventAddCallback(EV_P_ ev_async *w, int revents)
786 /* get the control command... */
787 pthread_mutex_lock(&DBEventQueueMutex);
789 if (DBInboundEventQueues[0] == DBInboundEventQueue) {
790 DBInboundEventQueue = DBInboundEventQueues[1];
791 q = DBInboundEventQueues[0];
794 DBInboundEventQueue = DBInboundEventQueues[0];
795 q = DBInboundEventQueues[1];
797 pthread_mutex_unlock(&DBEventQueueMutex);
799 Now = ev_now (event_db);
800 It = GetNewHashPos(q, 0);
801 while (GetNextHashPos(q, It, &len, &Key, &v))
807 h->IO->ID = EvIDSource++;
809 if (h->IO->StartDB == 0.0)
810 h->IO->StartDB = Now;
811 h->IO->CitContext->lastcmd = h->IO->Now = Now;
813 SetEVState(h->IO, eDBAttach);
814 Ctx = h->IO->CitContext;
816 ev_cleanup_start(event_db, &h->IO->db_abort_by_shutdown);
817 rc = h->EvAttch(h->IO);
821 ShutDownDBCLient(h->IO);
827 DeleteHashContent(&q);
828 EVQ_syslog(LOG_DEBUG, "%s CC[%ld] DBEVENT Q Add %ld done.", IOSTR, IOID, count);
832 static void DBEventExitCallback(EV_P_ ev_async *w, int revents)
834 EVQM_syslog(LOG_DEBUG, "DB EVENT Q exiting.\n");
835 ev_break(event_db, EVBREAK_ALL);
840 void DBInitEventQueue(void)
842 pthread_mutex_init(&DBEventQueueMutex, NULL);
843 pthread_mutex_init(&DBEventExitQueueMutex, NULL);
845 DBQueueEvents = NewHash(1, Flathash);
846 DBInboundEventQueues[0] = NewHash(1, Flathash);
847 DBInboundEventQueues[1] = NewHash(1, Flathash);
848 DBInboundEventQueue = DBInboundEventQueues[0];
851 const char *DBLog = "BD";
854 * this thread operates writing to the message database via libev.
856 void *db_event_thread(void *arg)
859 struct CitContext libev_msg_CC;
861 pthread_setspecific(evConKey, DBLog);
863 CtdlFillSystemContext(&libev_msg_CC, "LibEv DB IO Thread");
865 EVQM_syslog(LOG_DEBUG, "dbevent_thread() initializing\n");
867 tmp = event_db = ev_loop_new (EVFLAG_AUTO);
869 ev_async_init(&DBAddJob, DBQueueEventAddCallback);
870 ev_async_start(event_db, &DBAddJob);
871 ev_async_init(&DBExitEventLoop, DBEventExitCallback);
872 ev_async_start(event_db, &DBExitEventLoop);
874 ev_run (event_db, 0);
876 pthread_mutex_lock(&DBEventExitQueueMutex);
879 EVQM_syslog(LOG_INFO, "dbevent_thread() exiting\n");
881 DeleteHash(&DBQueueEvents);
882 DBInboundEventQueue = NULL;
883 DeleteHash(&DBInboundEventQueues[0]);
884 DeleteHash(&DBInboundEventQueues[1]);
886 /* citthread_mutex_destroy(&DBEventQueueMutex); TODO */
888 ev_loop_destroy (tmp);
889 pthread_mutex_unlock(&DBEventExitQueueMutex);
893 void ShutDownEventQueues(void)
895 EVQM_syslog(LOG_DEBUG, "EVENT Qs triggering exits.\n");
897 pthread_mutex_lock(&DBEventQueueMutex);
898 ev_async_send (event_db, &DBExitEventLoop);
899 pthread_mutex_unlock(&DBEventQueueMutex);
901 pthread_mutex_lock(&EventQueueMutex);
902 ev_async_send (EV_DEFAULT_ &ExitEventLoop);
903 pthread_mutex_unlock(&EventQueueMutex);
906 void DebugEventloopEnable(const int n)
910 void DebugEventloopBacktraceEnable(const int n)
912 DebugEventLoopBacktrace = n;
915 void DebugCurlEnable(const int n)
920 const char *WLog = "WX";
921 CTDL_MODULE_INIT(event_client)
925 if (pthread_key_create(&evConKey, NULL) != 0) {
926 syslog(LOG_CRIT, "Can't create TSD key: %s", strerror(errno));
928 pthread_setspecific(evConKey, WLog);
930 CtdlRegisterDebugFlagHook(HKEY("eventloop"), DebugEventloopEnable, &DebugEventLoop);
931 CtdlRegisterDebugFlagHook(HKEY("eventloopbacktrace"), DebugEventloopBacktraceEnable, &DebugEventLoopBacktrace);
932 CtdlRegisterDebugFlagHook(HKEY("curl"), DebugCurlEnable, &DebugCurl);
935 CtdlThreadCreate(client_event_thread);
936 CtdlThreadCreate(db_event_thread);