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->CitContext->lastcmd = 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 IO->HttpReq.headers = NULL;
185 msta = curl_multi_remove_handle(global.mhnd, chnd);
187 EVCURL_syslog(LOG_ERR,
188 "warning problem detaching "
189 "completed handle from curl multi: "
191 curl_multi_strerror(msta));
193 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
195 IO->HttpReq.attached = 0;
196 switch(IO->SendDone(IO))
199 FreeURL(&IO->ConnectMe);
200 QueueAnDBOperation(IO);
213 case eTerminateConnection:
215 curl_easy_cleanup(IO->HttpReq.chnd);
216 IO->HttpReq.chnd = NULL;
217 FreeStrBuf(&IO->HttpReq.ReplyData);
218 FreeURL(&IO->ConnectMe);
219 RemoveContext(IO->CitContext);
227 stepmulti(void *data, curl_socket_t fd, int which)
229 int running_handles = 0;
232 msta = curl_multi_socket_action(global.mhnd,
237 CURLM_syslog(LOG_DEBUG, "stepmulti(): calling gotstatus()\n");
240 "error in curl processing events"
241 "on multi handle, fd %d: %s\n",
243 curl_multi_strerror(msta));
245 if (global.nrun != running_handles)
246 gotstatus(running_handles);
250 gottime(struct ev_loop *loop, ev_timer *timeev, int events)
252 CURLM_syslog(LOG_DEBUG, "EVCURL: waking up curl for timeout\n");
253 stepmulti(NULL, CURL_SOCKET_TIMEOUT, 0);
257 got_in(struct ev_loop *loop, ev_io *ioev, int events)
259 CURL_syslog(LOG_DEBUG,
260 "EVCURL: waking up curl for io on fd %d\n",
263 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_IN);
267 got_out(struct ev_loop *loop, ev_io *ioev, int events)
269 CURL_syslog(LOG_DEBUG,
270 "waking up curl for io on fd %d\n",
273 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_OUT);
277 gotdata(void *data, size_t size, size_t nmemb, void *cglobal)
279 AsyncIO *IO = (AsyncIO*) cglobal;
281 SetEVState(IO, eCurlGotData);
282 if (IO->HttpReq.ReplyData == NULL)
284 IO->HttpReq.ReplyData = NewStrBufPlain(NULL, SIZ);
286 IO->CitContext->lastcmd = IO->Now = ev_now(event_base);
287 return CurlFillStrBuf_callback(data,
290 IO->HttpReq.ReplyData);
294 gotwatchtime(CURLM *multi, long tblock_ms, void *cglobal) {
295 CURL_syslog(LOG_DEBUG, "EVCURL: gotwatchtime called %ld ms\n", tblock_ms);
296 evcurl_global_data *global = cglobal;
297 ev_timer_stop(EV_DEFAULT, &global->timeev);
298 if (tblock_ms < 0 || 14000 < tblock_ms)
300 ev_timer_set(&global->timeev, 0.5e-3 + 1.0e-3 * tblock_ms, 14.0);
301 ev_timer_start(EV_DEFAULT_UC, &global->timeev);
302 curl_multi_perform(global, &global->nrun);
307 gotwatchsock(CURL *easy,
313 evcurl_global_data *global = cglobal;
314 CURLM *mhnd = global->mhnd;
316 AsyncIO *IO = (AsyncIO*) vIO;
321 sta = curl_easy_getinfo(easy, CURLINFO_PRIVATE, &f);
324 "EVCURL: error asking curl for private "
325 "cookie of curl handle: %s\n",
326 curl_easy_strerror(sta));
330 SetEVState(IO, eCurlNewIO);
331 EVCURL_syslog(LOG_DEBUG,
332 "EVCURL: got socket for URL: %s\n",
333 IO->ConnectMe->PlainUrl);
335 if (IO->SendBuf.fd != 0)
337 ev_io_stop(event_base, &IO->recv_event);
338 ev_io_stop(event_base, &IO->send_event);
341 ev_io_init(&IO->recv_event, &got_in, fd, EV_READ);
342 ev_io_init(&IO->send_event, &got_out, fd, EV_WRITE);
343 curl_multi_assign(mhnd, fd, IO);
346 SetEVState(IO, eCurlGotIO);
347 IO->CitContext->lastcmd = IO->Now = ev_now(event_base);
353 Action = "CURL_POLL_NONE";
355 case CURL_POLL_REMOVE:
356 Action = "CURL_POLL_REMOVE";
359 Action = "CURL_POLL_IN";
362 Action = "CURL_POLL_OUT";
364 case CURL_POLL_INOUT:
365 Action = "CURL_POLL_INOUT";
370 EVCURL_syslog(LOG_DEBUG,
371 "EVCURL: gotwatchsock called fd=%d action=%s[%d]\n",
372 (int)fd, Action, action);
377 EVCURLM_syslog(LOG_DEBUG,
379 "to register this sockwatcker\n");
381 case CURL_POLL_REMOVE:
382 EVCURLM_syslog(LOG_DEBUG,
383 "called last time to unregister "
384 "this sockwatcher\n");
385 ev_io_stop(event_base, &IO->recv_event);
386 ev_io_stop(event_base, &IO->send_event);
389 ev_io_start(event_base, &IO->recv_event);
390 ev_io_stop(event_base, &IO->send_event);
393 ev_io_start(event_base, &IO->send_event);
394 ev_io_stop(event_base, &IO->recv_event);
396 case CURL_POLL_INOUT:
397 ev_io_start(event_base, &IO->send_event);
398 ev_io_start(event_base, &IO->recv_event);
404 void curl_init_connectionpool(void)
408 ev_timer_init(&global.timeev, &gottime, 14.0, 14.0);
409 global.timeev.data = (void *)&global;
411 CURLcode sta = curl_global_init(CURL_GLOBAL_ALL);
416 "error initializing curl library: %s\n",
417 curl_easy_strerror(sta));
421 mhnd = global.mhnd = curl_multi_init();
424 CURLM_syslog(LOG_ERR,
425 "error initializing curl multi handle\n");
429 MOPT(SOCKETFUNCTION, &gotwatchsock);
430 MOPT(SOCKETDATA, (void *)&global);
431 MOPT(TIMERFUNCTION, &gotwatchtime);
432 MOPT(TIMERDATA, (void *)&global);
437 int evcurl_init(AsyncIO *IO)
442 EVCURLM_syslog(LOG_DEBUG, "EVCURL: evcurl_init called ms\n");
443 IO->HttpReq.attached = 0;
444 chnd = IO->HttpReq.chnd = curl_easy_init();
447 EVCURLM_syslog(LOG_ERR, "EVCURL: error initializing curl handle\n");
452 OPT(VERBOSE, (long)1);
457 OPT(FAILONERROR, (long)1);
459 OPT(FOLLOWLOCATION, (long)0);
460 OPT(MAXREDIRS, (long)0);
461 OPT(USERAGENT, CITADEL);
463 OPT(TIMEOUT, (long)1800);
464 OPT(LOW_SPEED_LIMIT, (long)64);
465 OPT(LOW_SPEED_TIME, (long)600);
466 OPT(CONNECTTIMEOUT, (long)600);
467 OPT(PRIVATE, (void *)IO);
469 OPT(FORBID_REUSE, 1);
470 OPT(WRITEFUNCTION, &gotdata);
471 OPT(WRITEDATA, (void *)IO);
472 OPT(ERRORBUFFER, IO->HttpReq.errdesc);
474 if ((!IsEmptyStr(CtdlGetConfigStr("c_ip_addr")))
475 && (strcmp(CtdlGetConfigStr("c_ip_addr"), "*"))
476 && (strcmp(CtdlGetConfigStr("c_ip_addr"), "::"))
477 && (strcmp(CtdlGetConfigStr("c_ip_addr"), "0.0.0.0"))
480 OPT(INTERFACE, CtdlGetConfigStr("c_ip_addr"));
483 #ifdef CURLOPT_HTTP_CONTENT_DECODING
484 OPT(HTTP_CONTENT_DECODING, 1);
488 IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers,
489 "Connection: close");
495 static void IOcurl_abort_shutdown_callback(struct ev_loop *loop,
500 AsyncIO *IO = watcher->data;
505 SetEVState(IO, eCurlShutdown);
506 IO->CitContext->lastcmd = IO->Now = ev_now(event_base);
507 EVCURL_syslog(LOG_DEBUG, "EVENT Curl: %s\n", __FUNCTION__);
509 curl_slist_free_all(IO->HttpReq.headers);
510 IO->HttpReq.headers = NULL;
511 msta = curl_multi_remove_handle(global.mhnd, IO->HttpReq.chnd);
514 EVCURL_syslog(LOG_ERR,
515 "EVCURL: warning problem detaching completed handle "
516 "from curl multi: %s\n",
517 curl_multi_strerror(msta));
520 curl_easy_cleanup(IO->HttpReq.chnd);
521 IO->HttpReq.chnd = NULL;
522 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
523 ev_io_stop(event_base, &IO->recv_event);
524 ev_io_stop(event_base, &IO->send_event);
525 assert(IO->ShutdownAbort);
526 IO->ShutdownAbort(IO);
530 evcurl_handle_start(AsyncIO *IO)
536 SetEVState(IO, eCurlStart);
537 chnd = IO->HttpReq.chnd;
538 EVCURL_syslog(LOG_DEBUG,
539 "EVCURL: Loading URL: %s\n", IO->ConnectMe->PlainUrl);
540 OPT(URL, IO->ConnectMe->PlainUrl);
541 if (StrLength(IO->ConnectMe->CurlCreds))
543 OPT(HTTPAUTH, (long)CURLAUTH_BASIC);
544 OPT(USERPWD, ChrPtr(IO->ConnectMe->CurlCreds));
546 if (StrLength(IO->HttpReq.PostData) > 0)
548 OPT(POSTFIELDS, ChrPtr(IO->HttpReq.PostData));
549 OPT(POSTFIELDSIZE, StrLength(IO->HttpReq.PostData));
552 else if ((IO->HttpReq.PlainPostDataLen != 0) &&
553 (IO->HttpReq.PlainPostData != NULL))
555 OPT(POSTFIELDS, IO->HttpReq.PlainPostData);
556 OPT(POSTFIELDSIZE, IO->HttpReq.PlainPostDataLen);
558 OPT(HTTPHEADER, IO->HttpReq.headers);
560 IO->NextState = eConnect;
561 EVCURLM_syslog(LOG_DEBUG, "EVCURL: attaching to curl multi handle\n");
562 msta = curl_multi_add_handle(global.mhnd, IO->HttpReq.chnd);
565 EVCURL_syslog(LOG_ERR,
566 "EVCURL: error attaching to curl multi handle: %s\n",
567 curl_multi_strerror(msta));
570 IO->HttpReq.attached = 1;
571 ev_async_send (event_base, &WakeupCurl);
573 ev_cleanup_init(&IO->abort_by_shutdown,
574 IOcurl_abort_shutdown_callback);
576 ev_cleanup_start(event_base, &IO->abort_by_shutdown);
581 static void WakeupCurlCallback(EV_P_ ev_async *w, int revents)
583 CURLM_syslog(LOG_DEBUG, "waking up curl multi handle\n");
585 curl_multi_perform(&global, CURL_POLL_NONE);
588 static void evcurl_shutdown (void)
590 curl_global_cleanup();
591 curl_multi_cleanup(global.mhnd);
592 CURLM_syslog(LOG_DEBUG, "exiting\n");
594 /*****************************************************************************
595 * libevent integration *
596 *****************************************************************************/
598 * client event queue plus its methods.
599 * this currently is the main loop (which may change in some future?)
601 int evbase_count = 0;
602 pthread_mutex_t EventQueueMutex; /* locks the access to the following vars: */
603 pthread_mutex_t EventExitQueueMutex; /* locks the access to the event queue pointer on exit. */
604 HashList *QueueEvents = NULL;
605 HashList *InboundEventQueue = NULL;
606 HashList *InboundEventQueues[2] = { NULL, NULL };
607 extern void ShutDownCLient(AsyncIO *IO);
610 ev_async ExitEventLoop;
612 static void QueueEventAddCallback(EV_P_ ev_async *w, int revents)
624 /* get the control command... */
625 pthread_mutex_lock(&EventQueueMutex);
627 if (InboundEventQueues[0] == InboundEventQueue) {
628 InboundEventQueue = InboundEventQueues[1];
629 q = InboundEventQueues[0];
632 InboundEventQueue = InboundEventQueues[0];
633 q = InboundEventQueues[1];
635 pthread_mutex_unlock(&EventQueueMutex);
636 Now = ev_now (event_base);
637 It = GetNewHashPos(q, 0);
638 while (GetNextHashPos(q, It, &len, &Key, &v))
642 if (h->IO->ID == 0) {
643 h->IO->ID = EvIDSource++;
646 if (h->IO->StartIO == 0.0)
647 h->IO->StartIO = Now;
649 SetEVState(h->IO, eIOAttach);
651 Ctx = h->IO->CitContext;
654 h->IO->CitContext->lastcmd = h->IO->Now = Now;
655 switch (h->EvAttch(h->IO))
669 case eTerminateConnection:
671 ShutDownCLient(h->IO);
676 DeleteHashContent(&q);
677 EVQ_syslog(LOG_DEBUG, "%s CC[%ld] EVENT Q Add %ld done.", IOSTR, IOID, count);
681 static void EventExitCallback(EV_P_ ev_async *w, int revents)
683 ev_break(event_base, EVBREAK_ALL);
685 EVQM_syslog(LOG_DEBUG, "EVENT Q exiting.\n");
690 void InitEventQueue(void)
692 pthread_mutex_init(&EventQueueMutex, NULL);
693 pthread_mutex_init(&EventExitQueueMutex, NULL);
695 QueueEvents = NewHash(1, Flathash);
696 InboundEventQueues[0] = NewHash(1, Flathash);
697 InboundEventQueues[1] = NewHash(1, Flathash);
698 InboundEventQueue = InboundEventQueues[0];
700 extern void CtdlDestroyEVCleanupHooks(void);
702 extern int EVQShutDown;
703 const char *IOLog = "IO";
705 * this thread operates the select() etc. via libev.
707 void *client_event_thread(void *arg)
709 struct CitContext libev_client_CC;
711 CtdlFillSystemContext(&libev_client_CC, "LibEv Thread");
713 pthread_setspecific(evConKey, IOLog);
715 EVQM_syslog(LOG_DEBUG, "client_event_thread() initializing\n");
717 event_base = ev_default_loop (EVFLAG_AUTO);
718 ev_async_init(&AddJob, QueueEventAddCallback);
719 ev_async_start(event_base, &AddJob);
720 ev_async_init(&ExitEventLoop, EventExitCallback);
721 ev_async_start(event_base, &ExitEventLoop);
722 ev_async_init(&WakeupCurl, WakeupCurlCallback);
723 ev_async_start(event_base, &WakeupCurl);
725 curl_init_connectionpool();
727 ev_run (event_base, 0);
729 EVQM_syslog(LOG_DEBUG, "client_event_thread() exiting\n");
731 ///what todo here? CtdlClearSystemContext();
732 pthread_mutex_lock(&EventExitQueueMutex);
733 ev_loop_destroy (EV_DEFAULT_UC);
735 DeleteHash(&QueueEvents);
736 InboundEventQueue = NULL;
737 DeleteHash(&InboundEventQueues[0]);
738 DeleteHash(&InboundEventQueues[1]);
739 /* citthread_mutex_destroy(&EventQueueMutex); TODO */
742 CtdlDestroyEVCleanupHooks();
744 pthread_mutex_unlock(&EventExitQueueMutex);
749 /*----------------------------------------------------------------------------*/
751 * DB-Queue; does async bdb operations.
752 * has its own set of handlers.
756 pthread_mutex_t DBEventQueueMutex; /* locks the access to the following vars: */
757 pthread_mutex_t DBEventExitQueueMutex; /* locks the access to the db-event queue pointer on exit. */
758 HashList *DBQueueEvents = NULL;
759 HashList *DBInboundEventQueue = NULL;
760 HashList *DBInboundEventQueues[2] = { NULL, NULL };
763 ev_async DBExitEventLoop;
765 extern void ShutDownDBCLient(AsyncIO *IO);
767 static void DBQueueEventAddCallback(EV_P_ ev_async *w, int revents)
779 /* get the control command... */
780 pthread_mutex_lock(&DBEventQueueMutex);
782 if (DBInboundEventQueues[0] == DBInboundEventQueue) {
783 DBInboundEventQueue = DBInboundEventQueues[1];
784 q = DBInboundEventQueues[0];
787 DBInboundEventQueue = DBInboundEventQueues[0];
788 q = DBInboundEventQueues[1];
790 pthread_mutex_unlock(&DBEventQueueMutex);
792 Now = ev_now (event_db);
793 It = GetNewHashPos(q, 0);
794 while (GetNextHashPos(q, It, &len, &Key, &v))
800 h->IO->ID = EvIDSource++;
802 if (h->IO->StartDB == 0.0)
803 h->IO->StartDB = Now;
804 h->IO->CitContext->lastcmd = h->IO->Now = Now;
806 SetEVState(h->IO, eDBAttach);
807 Ctx = h->IO->CitContext;
809 ev_cleanup_start(event_db, &h->IO->db_abort_by_shutdown);
810 rc = h->EvAttch(h->IO);
814 ShutDownDBCLient(h->IO);
820 DeleteHashContent(&q);
821 EVQ_syslog(LOG_DEBUG, "%s CC[%ld] DBEVENT Q Add %ld done.", IOSTR, IOID, count);
825 static void DBEventExitCallback(EV_P_ ev_async *w, int revents)
827 EVQM_syslog(LOG_DEBUG, "DB EVENT Q exiting.\n");
828 ev_break(event_db, EVBREAK_ALL);
833 void DBInitEventQueue(void)
835 pthread_mutex_init(&DBEventQueueMutex, NULL);
836 pthread_mutex_init(&DBEventExitQueueMutex, NULL);
838 DBQueueEvents = NewHash(1, Flathash);
839 DBInboundEventQueues[0] = NewHash(1, Flathash);
840 DBInboundEventQueues[1] = NewHash(1, Flathash);
841 DBInboundEventQueue = DBInboundEventQueues[0];
844 const char *DBLog = "BD";
847 * this thread operates writing to the message database via libev.
849 void *db_event_thread(void *arg)
852 struct CitContext libev_msg_CC;
854 pthread_setspecific(evConKey, DBLog);
856 CtdlFillSystemContext(&libev_msg_CC, "LibEv DB IO Thread");
858 EVQM_syslog(LOG_DEBUG, "dbevent_thread() initializing\n");
860 tmp = event_db = ev_loop_new (EVFLAG_AUTO);
862 ev_async_init(&DBAddJob, DBQueueEventAddCallback);
863 ev_async_start(event_db, &DBAddJob);
864 ev_async_init(&DBExitEventLoop, DBEventExitCallback);
865 ev_async_start(event_db, &DBExitEventLoop);
867 ev_run (event_db, 0);
869 pthread_mutex_lock(&DBEventExitQueueMutex);
872 EVQM_syslog(LOG_INFO, "dbevent_thread() exiting\n");
874 DeleteHash(&DBQueueEvents);
875 DBInboundEventQueue = NULL;
876 DeleteHash(&DBInboundEventQueues[0]);
877 DeleteHash(&DBInboundEventQueues[1]);
879 /* citthread_mutex_destroy(&DBEventQueueMutex); TODO */
881 ev_loop_destroy (tmp);
882 pthread_mutex_unlock(&DBEventExitQueueMutex);
886 void ShutDownEventQueues(void)
888 EVQM_syslog(LOG_DEBUG, "EVENT Qs triggering exits.\n");
890 pthread_mutex_lock(&DBEventQueueMutex);
891 ev_async_send (event_db, &DBExitEventLoop);
892 pthread_mutex_unlock(&DBEventQueueMutex);
894 pthread_mutex_lock(&EventQueueMutex);
895 ev_async_send (EV_DEFAULT_ &ExitEventLoop);
896 pthread_mutex_unlock(&EventQueueMutex);
899 void DebugEventloopEnable(const int n)
903 void DebugEventloopBacktraceEnable(const int n)
905 DebugEventLoopBacktrace = n;
908 void DebugCurlEnable(const int n)
913 const char *WLog = "WX";
914 CTDL_MODULE_INIT(event_client)
918 if (pthread_key_create(&evConKey, NULL) != 0) {
919 syslog(LOG_CRIT, "Can't create TSD key: %s", strerror(errno));
921 pthread_setspecific(evConKey, WLog);
923 CtdlRegisterDebugFlagHook(HKEY("eventloop"), DebugEventloopEnable, &DebugEventLoop);
924 CtdlRegisterDebugFlagHook(HKEY("eventloopbacktrace"), DebugEventloopBacktraceEnable, &DebugEventLoopBacktrace);
925 CtdlRegisterDebugFlagHook(HKEY("curl"), DebugCurlEnable, &DebugCurl);
928 CtdlThreadCreate(client_event_thread);
929 CtdlThreadCreate(db_event_thread);