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;
118 CURLM_syslog(LOG_DEBUG,
119 "gotstatus(): about to call curl_multi_info_read\n");
120 while ((msg = curl_multi_info_read(global.mhnd, &nmsg))) {
121 CURL_syslog(LOG_DEBUG,
122 "got curl multi_info message msg=%d\n",
125 if (CURLMSG_DONE == msg->msg) {
127 char *chandle = NULL;
133 chnd = msg->easy_handle;
134 sta = curl_easy_getinfo(chnd,
139 "error asking curl for private"
140 " cookie of curl handle: %s\n",
141 curl_easy_strerror(sta));
144 IO = (AsyncIO *)chandle;
146 EVCURL_syslog(LOG_ERR,
147 "Error, invalid IO context %p\n",
151 SetEVState(IO, eCurlGotStatus);
153 EVCURLM_syslog(LOG_DEBUG, "request complete\n");
155 IO->Now = ev_now(event_base);
157 ev_io_stop(event_base, &IO->recv_event);
158 ev_io_stop(event_base, &IO->send_event);
160 sta = msg->data.result;
162 EVCURL_syslog(LOG_ERR,
163 "error description: %s\n",
164 IO->HttpReq.errdesc);
165 IO->HttpReq.CurlError = curl_easy_strerror(sta);
166 EVCURL_syslog(LOG_ERR,
167 "error performing request: %s\n",
168 IO->HttpReq.CurlError);
169 if (sta == CURLE_OPERATION_TIMEDOUT)
175 sta = curl_easy_getinfo(chnd,
176 CURLINFO_RESPONSE_CODE,
177 &IO->HttpReq.httpcode);
179 EVCURL_syslog(LOG_ERR,
180 "error asking curl for "
181 "response code from request: %s\n",
182 curl_easy_strerror(sta));
183 EVCURL_syslog(LOG_DEBUG,
184 "http response code was %ld\n",
185 (long)IO->HttpReq.httpcode);
188 curl_slist_free_all(IO->HttpReq.headers);
189 msta = curl_multi_remove_handle(global.mhnd, chnd);
191 EVCURL_syslog(LOG_ERR,
192 "warning problem detaching "
193 "completed handle from curl multi: "
195 curl_multi_strerror(msta));
197 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
199 IO->HttpReq.attached = 0;
200 switch(IO->SendDone(IO))
214 case eTerminateConnection:
216 curl_easy_cleanup(IO->HttpReq.chnd);
217 IO->HttpReq.chnd = NULL;
218 FreeStrBuf(&IO->HttpReq.ReplyData);
219 FreeURL(&IO->ConnectMe);
220 RemoveContext(IO->CitContext);
228 stepmulti(void *data, curl_socket_t fd, int which)
230 int running_handles = 0;
233 msta = curl_multi_socket_action(global.mhnd,
238 CURLM_syslog(LOG_DEBUG, "stepmulti(): calling gotstatus()\n");
241 "error in curl processing events"
242 "on multi handle, fd %d: %s\n",
244 curl_multi_strerror(msta));
246 if (global.nrun != running_handles)
247 gotstatus(running_handles);
251 gottime(struct ev_loop *loop, ev_timer *timeev, int events)
253 CURLM_syslog(LOG_DEBUG, "EVCURL: waking up curl for timeout\n");
254 stepmulti(NULL, CURL_SOCKET_TIMEOUT, 0);
258 got_in(struct ev_loop *loop, ev_io *ioev, int events)
260 CURL_syslog(LOG_DEBUG,
261 "EVCURL: waking up curl for io on fd %d\n",
264 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_IN);
268 got_out(struct ev_loop *loop, ev_io *ioev, int events)
270 CURL_syslog(LOG_DEBUG,
271 "waking up curl for io on fd %d\n",
274 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_OUT);
278 gotdata(void *data, size_t size, size_t nmemb, void *cglobal)
280 AsyncIO *IO = (AsyncIO*) cglobal;
282 SetEVState(IO, eCurlGotData);
283 if (IO->HttpReq.ReplyData == NULL)
285 IO->HttpReq.ReplyData = NewStrBufPlain(NULL, SIZ);
287 IO->Now = ev_now(event_base);
288 return CurlFillStrBuf_callback(data,
291 IO->HttpReq.ReplyData);
295 gotwatchtime(CURLM *multi, long tblock_ms, void *cglobal) {
296 CURL_syslog(LOG_DEBUG, "EVCURL: gotwatchtime called %ld ms\n", tblock_ms);
297 evcurl_global_data *global = cglobal;
298 ev_timer_stop(EV_DEFAULT, &global->timeev);
299 if (tblock_ms < 0 || 14000 < tblock_ms)
301 ev_timer_set(&global->timeev, 0.5e-3 + 1.0e-3 * tblock_ms, 14.0);
302 ev_timer_start(EV_DEFAULT_UC, &global->timeev);
303 curl_multi_perform(global, &global->nrun);
308 gotwatchsock(CURL *easy,
314 evcurl_global_data *global = cglobal;
315 CURLM *mhnd = global->mhnd;
317 AsyncIO *IO = (AsyncIO*) vIO;
322 sta = curl_easy_getinfo(easy, CURLINFO_PRIVATE, &f);
325 "EVCURL: error asking curl for private "
326 "cookie of curl handle: %s\n",
327 curl_easy_strerror(sta));
331 SetEVState(IO, eCurlNewIO);
332 EVCURL_syslog(LOG_DEBUG,
333 "EVCURL: got socket for URL: %s\n",
334 IO->ConnectMe->PlainUrl);
336 if (IO->SendBuf.fd != 0)
338 ev_io_stop(event_base, &IO->recv_event);
339 ev_io_stop(event_base, &IO->send_event);
342 ev_io_init(&IO->recv_event, &got_in, fd, EV_READ);
343 ev_io_init(&IO->send_event, &got_out, fd, EV_WRITE);
344 curl_multi_assign(mhnd, fd, IO);
347 SetEVState(IO, eCurlGotIO);
348 IO->Now = ev_now(event_base);
354 Action = "CURL_POLL_NONE";
356 case CURL_POLL_REMOVE:
357 Action = "CURL_POLL_REMOVE";
360 Action = "CURL_POLL_IN";
363 Action = "CURL_POLL_OUT";
365 case CURL_POLL_INOUT:
366 Action = "CURL_POLL_INOUT";
371 EVCURL_syslog(LOG_DEBUG,
372 "EVCURL: gotwatchsock called fd=%d action=%s[%d]\n",
373 (int)fd, Action, action);
378 EVCURLM_syslog(LOG_DEBUG,
380 "to register this sockwatcker\n");
382 case CURL_POLL_REMOVE:
383 EVCURLM_syslog(LOG_DEBUG,
384 "called last time to unregister "
385 "this sockwatcher\n");
386 ev_io_stop(event_base, &IO->recv_event);
387 ev_io_stop(event_base, &IO->send_event);
390 ev_io_start(event_base, &IO->recv_event);
391 ev_io_stop(event_base, &IO->send_event);
394 ev_io_start(event_base, &IO->send_event);
395 ev_io_stop(event_base, &IO->recv_event);
397 case CURL_POLL_INOUT:
398 ev_io_start(event_base, &IO->send_event);
399 ev_io_start(event_base, &IO->recv_event);
405 void curl_init_connectionpool(void)
409 ev_timer_init(&global.timeev, &gottime, 14.0, 14.0);
410 global.timeev.data = (void *)&global;
412 CURLcode sta = curl_global_init(CURL_GLOBAL_ALL);
417 "error initializing curl library: %s\n",
418 curl_easy_strerror(sta));
422 mhnd = global.mhnd = curl_multi_init();
425 CURLM_syslog(LOG_ERR,
426 "error initializing curl multi handle\n");
430 MOPT(SOCKETFUNCTION, &gotwatchsock);
431 MOPT(SOCKETDATA, (void *)&global);
432 MOPT(TIMERFUNCTION, &gotwatchtime);
433 MOPT(TIMERDATA, (void *)&global);
438 int evcurl_init(AsyncIO *IO)
443 EVCURLM_syslog(LOG_DEBUG, "EVCURL: evcurl_init called ms\n");
444 IO->HttpReq.attached = 0;
445 chnd = IO->HttpReq.chnd = curl_easy_init();
448 EVCURLM_syslog(LOG_ERR, "EVCURL: error initializing curl handle\n");
453 OPT(VERBOSE, (long)1);
458 OPT(FAILONERROR, (long)1);
460 OPT(FOLLOWLOCATION, (long)0);
461 OPT(MAXREDIRS, (long)0);
462 OPT(USERAGENT, CITADEL);
464 OPT(TIMEOUT, (long)1800);
465 OPT(LOW_SPEED_LIMIT, (long)64);
466 OPT(LOW_SPEED_TIME, (long)600);
467 OPT(CONNECTTIMEOUT, (long)600);
468 OPT(PRIVATE, (void *)IO);
470 OPT(FORBID_REUSE, 1);
471 OPT(WRITEFUNCTION, &gotdata);
472 OPT(WRITEDATA, (void *)IO);
473 OPT(ERRORBUFFER, IO->HttpReq.errdesc);
475 if ((!IsEmptyStr(config.c_ip_addr))
476 && (strcmp(config.c_ip_addr, "*"))
477 && (strcmp(config.c_ip_addr, "::"))
478 && (strcmp(config.c_ip_addr, "0.0.0.0"))
481 OPT(INTERFACE, config.c_ip_addr);
484 #ifdef CURLOPT_HTTP_CONTENT_DECODING
485 OPT(HTTP_CONTENT_DECODING, 1);
489 IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers,
490 "Connection: close");
496 static void IOcurl_abort_shutdown_callback(struct ev_loop *loop,
501 AsyncIO *IO = watcher->data;
506 SetEVState(IO, eCurlShutdown);
507 IO->Now = ev_now(event_base);
508 EVCURL_syslog(LOG_DEBUG, "EVENT Curl: %s\n", __FUNCTION__);
510 curl_slist_free_all(IO->HttpReq.headers);
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);
529 evcurl_handle_start(AsyncIO *IO)
535 SetEVState(IO, eCurlStart);
536 chnd = IO->HttpReq.chnd;
537 EVCURL_syslog(LOG_DEBUG,
538 "EVCURL: Loading URL: %s\n", IO->ConnectMe->PlainUrl);
539 OPT(URL, IO->ConnectMe->PlainUrl);
540 if (StrLength(IO->ConnectMe->CurlCreds))
542 OPT(HTTPAUTH, (long)CURLAUTH_BASIC);
543 OPT(USERPWD, ChrPtr(IO->ConnectMe->CurlCreds));
545 if (StrLength(IO->HttpReq.PostData) > 0)
547 OPT(POSTFIELDS, ChrPtr(IO->HttpReq.PostData));
548 OPT(POSTFIELDSIZE, StrLength(IO->HttpReq.PostData));
551 else if ((IO->HttpReq.PlainPostDataLen != 0) &&
552 (IO->HttpReq.PlainPostData != NULL))
554 OPT(POSTFIELDS, IO->HttpReq.PlainPostData);
555 OPT(POSTFIELDSIZE, IO->HttpReq.PlainPostDataLen);
557 OPT(HTTPHEADER, IO->HttpReq.headers);
559 IO->NextState = eConnect;
560 EVCURLM_syslog(LOG_DEBUG, "EVCURL: attaching to curl multi handle\n");
561 msta = curl_multi_add_handle(global.mhnd, IO->HttpReq.chnd);
564 EVCURL_syslog(LOG_ERR,
565 "EVCURL: error attaching to curl multi handle: %s\n",
566 curl_multi_strerror(msta));
569 IO->HttpReq.attached = 1;
570 ev_async_send (event_base, &WakeupCurl);
572 ev_cleanup_init(&IO->abort_by_shutdown,
573 IOcurl_abort_shutdown_callback);
575 ev_cleanup_start(event_base, &IO->abort_by_shutdown);
580 static void WakeupCurlCallback(EV_P_ ev_async *w, int revents)
582 CURLM_syslog(LOG_DEBUG, "waking up curl multi handle\n");
584 curl_multi_perform(&global, CURL_POLL_NONE);
587 static void evcurl_shutdown (void)
589 curl_global_cleanup();
590 curl_multi_cleanup(global.mhnd);
591 CURLM_syslog(LOG_DEBUG, "exiting\n");
593 /*****************************************************************************
594 * libevent integration *
595 *****************************************************************************/
597 * client event queue plus its methods.
598 * this currently is the main loop (which may change in some future?)
600 int evbase_count = 0;
601 pthread_mutex_t EventQueueMutex; /* locks the access to the following vars: */
602 pthread_mutex_t EventExitQueueMutex; /* locks the access to the event queue pointer on exit. */
603 HashList *QueueEvents = NULL;
604 HashList *InboundEventQueue = NULL;
605 HashList *InboundEventQueues[2] = { NULL, NULL };
606 extern void ShutDownCLient(AsyncIO *IO);
609 ev_async ExitEventLoop;
611 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))
638 if (h->IO->ID == 0) {
639 h->IO->ID = EvIDSource++;
641 if (h->IO->StartIO == 0.0)
642 h->IO->StartIO = Now;
644 SetEVState(h->IO, eIOAttach);
646 Ctx = h->IO->CitContext;
650 switch (h->EvAttch(h->IO))
664 case eTerminateConnection:
666 ShutDownCLient(h->IO);
671 DeleteHashContent(&q);
672 EVQM_syslog(LOG_DEBUG, "EVENT Q Add done.\n");
676 static void EventExitCallback(EV_P_ ev_async *w, int revents)
678 ev_break(event_base, EVBREAK_ALL);
680 EVQM_syslog(LOG_DEBUG, "EVENT Q exiting.\n");
685 void InitEventQueue(void)
687 pthread_mutex_init(&EventQueueMutex, NULL);
688 pthread_mutex_init(&EventExitQueueMutex, NULL);
690 QueueEvents = NewHash(1, Flathash);
691 InboundEventQueues[0] = NewHash(1, Flathash);
692 InboundEventQueues[1] = NewHash(1, Flathash);
693 InboundEventQueue = InboundEventQueues[0];
695 extern void CtdlDestroyEVCleanupHooks(void);
697 extern int EVQShutDown;
698 const char *IOLog = "IO";
700 * this thread operates the select() etc. via libev.
702 void *client_event_thread(void *arg)
704 struct CitContext libev_client_CC;
706 CtdlFillSystemContext(&libev_client_CC, "LibEv Thread");
708 pthread_setspecific(evConKey, IOLog);
710 EVQM_syslog(LOG_DEBUG, "client_event_thread() initializing\n");
712 event_base = ev_default_loop (EVFLAG_AUTO);
713 ev_async_init(&AddJob, QueueEventAddCallback);
714 ev_async_start(event_base, &AddJob);
715 ev_async_init(&ExitEventLoop, EventExitCallback);
716 ev_async_start(event_base, &ExitEventLoop);
717 ev_async_init(&WakeupCurl, WakeupCurlCallback);
718 ev_async_start(event_base, &WakeupCurl);
720 curl_init_connectionpool();
722 ev_run (event_base, 0);
724 EVQM_syslog(LOG_DEBUG, "client_event_thread() exiting\n");
726 ///what todo here? CtdlClearSystemContext();
727 pthread_mutex_lock(&EventExitQueueMutex);
728 ev_loop_destroy (EV_DEFAULT_UC);
730 DeleteHash(&QueueEvents);
731 InboundEventQueue = NULL;
732 DeleteHash(&InboundEventQueues[0]);
733 DeleteHash(&InboundEventQueues[1]);
734 /* citthread_mutex_destroy(&EventQueueMutex); TODO */
737 CtdlDestroyEVCleanupHooks();
739 pthread_mutex_unlock(&EventExitQueueMutex);
744 /*----------------------------------------------------------------------------*/
746 * DB-Queue; does async bdb operations.
747 * has its own set of handlers.
751 pthread_mutex_t DBEventQueueMutex; /* locks the access to the following vars: */
752 pthread_mutex_t DBEventExitQueueMutex; /* locks the access to the db-event queue pointer on exit. */
753 HashList *DBQueueEvents = NULL;
754 HashList *DBInboundEventQueue = NULL;
755 HashList *DBInboundEventQueues[2] = { NULL, NULL };
758 ev_async DBExitEventLoop;
760 extern void ShutDownDBCLient(AsyncIO *IO);
762 static void DBQueueEventAddCallback(EV_P_ ev_async *w, int revents)
772 /* get the control command... */
773 pthread_mutex_lock(&DBEventQueueMutex);
775 if (DBInboundEventQueues[0] == DBInboundEventQueue) {
776 DBInboundEventQueue = DBInboundEventQueues[1];
777 q = DBInboundEventQueues[0];
780 DBInboundEventQueue = DBInboundEventQueues[0];
781 q = DBInboundEventQueues[1];
783 pthread_mutex_unlock(&DBEventQueueMutex);
785 Now = ev_now (event_db);
786 It = GetNewHashPos(q, 0);
787 while (GetNextHashPos(q, It, &len, &Key, &v))
792 h->IO->ID = EvIDSource++;
793 if (h->IO->StartDB == 0.0)
794 h->IO->StartDB = Now;
797 SetEVState(h->IO, eDBAttach);
798 Ctx = h->IO->CitContext;
800 ev_cleanup_start(event_db, &h->IO->db_abort_by_shutdown);
801 rc = h->EvAttch(h->IO);
805 ShutDownDBCLient(h->IO);
811 DeleteHashContent(&q);
812 EVQM_syslog(LOG_DEBUG, "DBEVENT Q Add done.\n");
816 static void DBEventExitCallback(EV_P_ ev_async *w, int revents)
818 EVQM_syslog(LOG_DEBUG, "DB EVENT Q exiting.\n");
819 ev_break(event_db, EVBREAK_ALL);
824 void DBInitEventQueue(void)
826 pthread_mutex_init(&DBEventQueueMutex, NULL);
827 pthread_mutex_init(&DBEventExitQueueMutex, NULL);
829 DBQueueEvents = NewHash(1, Flathash);
830 DBInboundEventQueues[0] = NewHash(1, Flathash);
831 DBInboundEventQueues[1] = NewHash(1, Flathash);
832 DBInboundEventQueue = DBInboundEventQueues[0];
835 const char *DBLog = "BD";
838 * this thread operates writing to the message database via libev.
840 void *db_event_thread(void *arg)
843 struct CitContext libev_msg_CC;
845 pthread_setspecific(evConKey, DBLog);
847 CtdlFillSystemContext(&libev_msg_CC, "LibEv DB IO Thread");
849 EVQM_syslog(LOG_DEBUG, "dbevent_thread() initializing\n");
851 tmp = event_db = ev_loop_new (EVFLAG_AUTO);
853 ev_async_init(&DBAddJob, DBQueueEventAddCallback);
854 ev_async_start(event_db, &DBAddJob);
855 ev_async_init(&DBExitEventLoop, DBEventExitCallback);
856 ev_async_start(event_db, &DBExitEventLoop);
858 ev_run (event_db, 0);
860 pthread_mutex_lock(&DBEventExitQueueMutex);
863 EVQM_syslog(LOG_INFO, "dbevent_thread() exiting\n");
865 DeleteHash(&DBQueueEvents);
866 DBInboundEventQueue = NULL;
867 DeleteHash(&DBInboundEventQueues[0]);
868 DeleteHash(&DBInboundEventQueues[1]);
870 /* citthread_mutex_destroy(&DBEventQueueMutex); TODO */
872 ev_loop_destroy (tmp);
873 pthread_mutex_unlock(&DBEventExitQueueMutex);
877 void ShutDownEventQueues(void)
879 EVQM_syslog(LOG_DEBUG, "EVENT Qs triggering exits.\n");
881 pthread_mutex_lock(&DBEventQueueMutex);
882 ev_async_send (event_db, &DBExitEventLoop);
883 pthread_mutex_unlock(&DBEventQueueMutex);
885 pthread_mutex_lock(&EventQueueMutex);
886 ev_async_send (EV_DEFAULT_ &ExitEventLoop);
887 pthread_mutex_unlock(&EventQueueMutex);
890 void DebugEventloopEnable(const int n)
894 void DebugEventloopBacktraceEnable(const int n)
896 DebugEventLoopBacktrace = n;
899 void DebugCurlEnable(const int n)
904 const char *WLog = "WX";
905 CTDL_MODULE_INIT(event_client)
909 if (pthread_key_create(&evConKey, NULL) != 0) {
910 syslog(LOG_CRIT, "Can't create TSD key: %s", strerror(errno));
912 pthread_setspecific(evConKey, WLog);
914 CtdlRegisterDebugFlagHook(HKEY("eventloop"), DebugEventloopEnable, &DebugEventLoop);
915 CtdlRegisterDebugFlagHook(HKEY("eventloopbacktrace"), DebugEventloopBacktraceEnable, &DebugEventLoopBacktrace);
916 CtdlRegisterDebugFlagHook(HKEY("curl"), DebugCurlEnable, &DebugCurl);
919 CtdlThreadCreate(client_event_thread);
920 CtdlThreadCreate(db_event_thread);