3 * Copyright (c) 1998-2012 by the citadel.org team
5 * This program is open source software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <sys/types.h>
32 #if TIME_WITH_SYS_TIME
33 # include <sys/time.h>
37 # include <sys/time.h>
46 #include <sys/socket.h>
47 #include <netinet/in.h>
48 #include <arpa/inet.h>
54 #include <libcitadel.h>
57 #include "citserver.h"
64 #include "internet_addressing.h"
67 #include "clientsocket.h"
68 #include "locate_host.h"
69 #include "citadel_dirs.h"
71 #include "event_client.h"
72 #include "ctdl_module.h"
74 static void IO_Timeout_callback(struct ev_loop *loop, ev_timer *watcher, int revents);
75 static void IO_abort_shutdown_callback(struct ev_loop *loop,
80 /*------------------------------------------------------------------------------
82 *----------------------------------------------------------------------------*/
83 extern int evdb_count;
84 extern pthread_mutex_t DBEventQueueMutex;
85 extern pthread_mutex_t DBEventExitQueueMutex;
86 extern HashList *DBInboundEventQueue;
87 extern struct ev_loop *event_db;
88 extern ev_async DBAddJob;
89 extern ev_async DBExitEventLoop;
91 eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB)
96 h = (IOAddHandler*)malloc(sizeof(IOAddHandler));
99 ev_cleanup_init(&IO->db_abort_by_shutdown,
100 IO_abort_shutdown_callback);
101 IO->db_abort_by_shutdown.data = IO;
103 pthread_mutex_lock(&DBEventQueueMutex);
104 if (DBInboundEventQueue == NULL)
106 /* shutting down... */
108 EVM_syslog(LOG_DEBUG, "DBEVENT Q exiting.\n");
109 pthread_mutex_unlock(&DBEventQueueMutex);
112 EVM_syslog(LOG_DEBUG, "DBEVENT Q\n");
114 Put(DBInboundEventQueue, IKEY(i), h, NULL);
115 pthread_mutex_unlock(&DBEventQueueMutex);
117 pthread_mutex_lock(&DBEventExitQueueMutex);
118 if (event_db == NULL)
120 pthread_mutex_unlock(&DBEventExitQueueMutex);
123 ev_async_send (event_db, &DBAddJob);
124 pthread_mutex_unlock(&DBEventExitQueueMutex);
126 EVM_syslog(LOG_DEBUG, "DBEVENT Q Done.\n");
130 void StopDBWatchers(AsyncIO *IO)
132 ev_cleanup_stop(event_db, &IO->db_abort_by_shutdown);
133 ev_idle_stop(event_db, &IO->db_unwind_stack);
136 void ShutDownDBCLient(AsyncIO *IO)
138 CitContext *Ctx =IO->CitContext;
141 EVM_syslog(LOG_DEBUG, "DBEVENT Terminating.\n");
144 assert(IO->DBTerminate);
149 DB_PerformNext(struct ev_loop *loop, ev_idle *watcher, int revents)
151 AsyncIO *IO = watcher->data;
152 IO->Now = ev_now(event_db);
153 EV_syslog(LOG_DEBUG, "%s()", __FUNCTION__);
154 become_session(IO->CitContext);
156 ev_idle_stop(event_db, &IO->db_unwind_stack);
158 assert(IO->NextDBOperation);
159 switch (IO->NextDBOperation(IO))
173 ev_cleanup_stop(loop, &IO->db_abort_by_shutdown);
175 case eTerminateConnection:
177 ev_idle_stop(event_db, &IO->db_unwind_stack);
178 ev_cleanup_stop(loop, &IO->db_abort_by_shutdown);
179 ShutDownDBCLient(IO);
183 eNextState NextDBOperation(AsyncIO *IO, IO_CallBack CB)
185 IO->NextDBOperation = CB;
186 ev_idle_init(&IO->db_unwind_stack,
188 IO->db_unwind_stack.data = IO;
189 ev_idle_start(event_db, &IO->db_unwind_stack);
193 /*------------------------------------------------------------------------------
195 *----------------------------------------------------------------------------*/
196 extern int evbase_count;
197 extern pthread_mutex_t EventQueueMutex;
198 extern pthread_mutex_t EventExitQueueMutex;
199 extern HashList *InboundEventQueue;
200 extern struct ev_loop *event_base;
201 extern ev_async AddJob;
202 extern ev_async ExitEventLoop;
204 static void IO_abort_shutdown_callback(struct ev_loop *loop,
208 AsyncIO *IO = watcher->data;
209 EV_syslog(LOG_DEBUG, "EVENT Q: %s\n", __FUNCTION__);
210 IO->Now = ev_now(event_base);
211 assert(IO->ShutdownAbort);
212 IO->ShutdownAbort(IO);
216 eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB)
221 h = (IOAddHandler*)malloc(sizeof(IOAddHandler));
224 ev_cleanup_init(&IO->abort_by_shutdown,
225 IO_abort_shutdown_callback);
226 IO->abort_by_shutdown.data = IO;
228 pthread_mutex_lock(&EventQueueMutex);
229 if (InboundEventQueue == NULL)
232 /* shutting down... */
233 EVM_syslog(LOG_DEBUG, "EVENT Q exiting.\n");
234 pthread_mutex_unlock(&EventQueueMutex);
237 EVM_syslog(LOG_DEBUG, "EVENT Q\n");
239 Put(InboundEventQueue, IKEY(i), h, NULL);
240 pthread_mutex_unlock(&EventQueueMutex);
242 pthread_mutex_lock(&EventExitQueueMutex);
243 if (event_base == NULL) {
244 pthread_mutex_unlock(&EventExitQueueMutex);
247 ev_async_send (event_base, &AddJob);
248 pthread_mutex_unlock(&EventExitQueueMutex);
249 EVM_syslog(LOG_DEBUG, "EVENT Q Done.\n");
253 extern eNextState evcurl_handle_start(AsyncIO *IO);
255 eNextState QueueCurlContext(AsyncIO *IO)
260 h = (IOAddHandler*)malloc(sizeof(IOAddHandler));
262 h->EvAttch = evcurl_handle_start;
264 pthread_mutex_lock(&EventQueueMutex);
265 if (InboundEventQueue == NULL)
267 /* shutting down... */
269 EVM_syslog(LOG_DEBUG, "EVENT Q exiting.\n");
270 pthread_mutex_unlock(&EventQueueMutex);
274 EVM_syslog(LOG_DEBUG, "EVENT Q\n");
276 Put(InboundEventQueue, IKEY(i), h, NULL);
277 pthread_mutex_unlock(&EventQueueMutex);
279 pthread_mutex_lock(&EventExitQueueMutex);
280 if (event_base == NULL) {
281 pthread_mutex_unlock(&EventExitQueueMutex);
284 ev_async_send (event_base, &AddJob);
285 pthread_mutex_unlock(&EventExitQueueMutex);
287 EVM_syslog(LOG_DEBUG, "EVENT Q Done.\n");
291 void DestructCAres(AsyncIO *IO);
292 void FreeAsyncIOContents(AsyncIO *IO)
294 CitContext *Ctx = IO->CitContext;
296 FreeStrBuf(&IO->IOBuf);
297 FreeStrBuf(&IO->SendBuf.Buf);
298 FreeStrBuf(&IO->RecvBuf.Buf);
302 FreeURL(&IO->ConnectMe);
303 FreeStrBuf(&IO->HttpReq.ReplyData);
306 Ctx->state = CON_IDLE;
312 void StopClientWatchers(AsyncIO *IO)
314 ev_timer_stop (event_base, &IO->rw_timeout);
315 ev_timer_stop(event_base, &IO->conn_fail);
316 ev_idle_stop(event_base, &IO->unwind_stack);
317 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
319 ev_io_stop(event_base, &IO->conn_event);
320 ev_io_stop(event_base, &IO->send_event);
321 ev_io_stop(event_base, &IO->recv_event);
323 if (IO->SendBuf.fd != 0) {
324 close(IO->SendBuf.fd);
330 void StopCurlWatchers(AsyncIO *IO)
332 ev_timer_stop (event_base, &IO->rw_timeout);
333 ev_timer_stop(event_base, &IO->conn_fail);
334 ev_idle_stop(event_base, &IO->unwind_stack);
335 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
337 ev_io_stop(event_base, &IO->conn_event);
338 ev_io_stop(event_base, &IO->send_event);
339 ev_io_stop(event_base, &IO->recv_event);
341 if (IO->SendBuf.fd != 0) {
342 close(IO->SendBuf.fd);
348 void ShutDownCLient(AsyncIO *IO)
350 CitContext *Ctx =IO->CitContext;
353 EVM_syslog(LOG_DEBUG, "EVENT Terminating \n");
355 StopClientWatchers(IO);
357 if (IO->DNS.Channel != NULL) {
358 ares_destroy(IO->DNS.Channel);
359 EV_DNS_LOG_STOP(DNS.recv_event);
360 EV_DNS_LOG_STOP(DNS.send_event);
361 ev_io_stop(event_base, &IO->DNS.recv_event);
362 ev_io_stop(event_base, &IO->DNS.send_event);
363 IO->DNS.Channel = NULL;
365 assert(IO->Terminate);
369 void PostInbound(AsyncIO *IO)
371 switch (IO->NextState) {
373 ev_io_start(event_base, &IO->send_event);
377 assert(IO->SendDone);
378 IO->NextState = IO->SendDone(IO);
379 ev_io_start(event_base, &IO->send_event);
384 ev_io_start(event_base, &IO->recv_event);
386 case eTerminateConnection:
400 eReadState HandleInbound(AsyncIO *IO)
402 const char *Err = NULL;
403 eReadState Finished = eBufferNotEmpty;
405 become_session(IO->CitContext);
407 while ((Finished == eBufferNotEmpty) &&
408 ((IO->NextState == eReadMessage)||
409 (IO->NextState == eReadMore)||
410 (IO->NextState == eReadFile)||
411 (IO->NextState == eReadPayload)))
414 * lex line reply in callback,
415 * or do it ourselves.
416 * i.e. as nnn-blabla means continue reading in SMTP
418 if ((IO->NextState == eReadFile) &&
419 (Finished == eBufferNotEmpty))
421 Finished = WriteIOBAlreadyRead(&IO->IOB, &Err);
422 if (Finished == eReadSuccess)
424 IO->NextState = eSendReply;
427 else if (IO->LineReader)
428 Finished = IO->LineReader(IO);
430 Finished = StrBufChunkSipLine(IO->IOBuf,
434 case eMustReadMore: /// read new from socket...
436 case eBufferNotEmpty: /* shouldn't happen... */
437 case eReadSuccess: /// done for now...
439 case eReadFail: /// WHUT?
444 if (Finished != eMustReadMore) {
445 assert(IO->ReadDone);
446 ev_io_stop(event_base, &IO->recv_event);
447 IO->NextState = IO->ReadDone(IO);
448 Finished = StrBufCheckBuffer(&IO->RecvBuf);
459 IO_send_callback(struct ev_loop *loop, ev_io *watcher, int revents)
462 AsyncIO *IO = watcher->data;
463 const char *errmsg = NULL;
465 IO->Now = ev_now(event_base);
466 become_session(IO->CitContext);
472 const char *pch = ChrPtr(IO->SendBuf.Buf);
473 const char *pchh = IO->SendBuf.ReadWritePointer;
479 nbytes = StrLength(IO->SendBuf.Buf) - (pchh - pch);
480 snprintf(fn, SIZ, "/tmp/foolog_ev_%s.%d",
481 ((CitContext*)(IO->CitContext))->ServiceName,
484 fd = fopen(fn, "a+");
485 fprintf(fd, "Send: BufSize: %ld BufContent: [",
487 rv = fwrite(pchh, nbytes, 1, fd);
488 if (!rv) printf("failed to write debug to %s!\n", fn);
491 switch (IO->NextState) {
493 rc = FileSendChunked(&IO->IOB, &errmsg);
495 StrBufPlain(IO->ErrMsg, errmsg, -1);
498 rc = StrBuf_write_one_chunk_callback(watcher->fd,
504 fprintf(fd, "Sent: BufSize: %d bytes.\n", rc);
510 ev_io_stop(event_base, &IO->send_event);
511 switch (IO->NextState) {
513 assert(IO->SendDone);
514 IO->NextState = IO->SendDone(IO);
516 if ((IO->NextState == eTerminateConnection) ||
517 (IO->NextState == eAbort) )
520 ev_io_start(event_base, &IO->send_event);
524 if (IO->IOB.ChunkSendRemain > 0) {
525 ev_io_start(event_base, &IO->recv_event);
526 SetNextTimeout(IO, 100.0);
529 assert(IO->ReadDone);
530 IO->NextState = IO->ReadDone(IO);
531 switch(IO->NextState) {
540 ev_io_start(event_base,
548 case eTerminateConnection:
555 if (StrBufCheckBuffer(&IO->SendBuf) != eReadSuccess)
557 IO->NextState = eReadMore;
562 if (StrBufCheckBuffer(&IO->RecvBuf) == eBufferNotEmpty)
567 ev_io_start(event_base, &IO->recv_event);
573 * we now live in another queue,
574 * so we have to unregister.
576 ev_cleanup_stop(loop, &IO->abort_by_shutdown);
581 case eTerminateConnection:
587 IO_Timeout_callback(loop, &IO->rw_timeout, revents);
589 /* else : must write more. */
592 set_start_callback(struct ev_loop *loop, AsyncIO *IO, int revents)
594 switch(IO->NextState) {
598 StrBufAppendBufPlain(IO->ErrMsg, HKEY("[while waiting for greeting]"), 0);
599 ev_io_start(event_base, &IO->recv_event);
605 become_session(IO->CitContext);
606 IO_send_callback(loop, &IO->send_event, revents);
612 case eTerminateConnection:
620 IO_Timeout_callback(struct ev_loop *loop, ev_timer *watcher, int revents)
622 AsyncIO *IO = watcher->data;
624 IO->Now = ev_now(event_base);
625 ev_timer_stop (event_base, &IO->rw_timeout);
626 become_session(IO->CitContext);
628 if (IO->SendBuf.fd != 0)
630 ev_io_stop(event_base, &IO->send_event);
631 ev_io_stop(event_base, &IO->recv_event);
632 ev_timer_stop (event_base, &IO->rw_timeout);
633 close(IO->SendBuf.fd);
634 IO->SendBuf.fd = IO->RecvBuf.fd = 0;
638 switch (IO->Timeout(IO))
648 IO_connfail_callback(struct ev_loop *loop, ev_timer *watcher, int revents)
650 AsyncIO *IO = watcher->data;
652 IO->Now = ev_now(event_base);
653 ev_timer_stop (event_base, &IO->conn_fail);
655 if (IO->SendBuf.fd != 0)
657 ev_io_stop(loop, &IO->conn_event);
658 ev_io_stop(event_base, &IO->send_event);
659 ev_io_stop(event_base, &IO->recv_event);
660 ev_timer_stop (event_base, &IO->rw_timeout);
661 close(IO->SendBuf.fd);
662 IO->SendBuf.fd = IO->RecvBuf.fd = 0;
664 become_session(IO->CitContext);
666 assert(IO->ConnFail);
667 switch (IO->ConnFail(IO))
678 IO_connfailimmediate_callback(struct ev_loop *loop,
682 AsyncIO *IO = watcher->data;
684 IO->Now = ev_now(event_base);
685 ev_idle_stop (event_base, &IO->conn_fail_immediate);
687 if (IO->SendBuf.fd != 0)
689 close(IO->SendBuf.fd);
690 IO->SendBuf.fd = IO->RecvBuf.fd = 0;
692 become_session(IO->CitContext);
694 assert(IO->ConnFail);
695 switch (IO->ConnFail(IO))
706 IO_connestd_callback(struct ev_loop *loop, ev_io *watcher, int revents)
708 AsyncIO *IO = watcher->data;
710 IO->Now = ev_now(event_base);
711 EVM_syslog(LOG_DEBUG, "connect() succeeded.\n");
713 ev_io_stop(loop, &IO->conn_event);
714 ev_timer_stop (event_base, &IO->conn_fail);
715 set_start_callback(loop, IO, revents);
718 IO_recv_callback(struct ev_loop *loop, ev_io *watcher, int revents)
722 AsyncIO *IO = watcher->data;
724 IO->Now = ev_now(event_base);
725 switch (IO->NextState) {
727 nbytes = FileRecvChunked(&IO->IOB, &errmsg);
729 StrBufPlain(IO->ErrMsg, errmsg, -1);
732 if (IO->IOB.ChunkSendRemain == 0)
734 IO->NextState = eSendReply;
735 assert(IO->ReadDone);
736 ev_io_stop(event_base, &IO->recv_event);
745 nbytes = StrBuf_read_one_chunk_callback(watcher->fd,
757 const char *pch = ChrPtr(IO->RecvBuf.Buf);
758 const char *pchh = IO->RecvBuf.ReadWritePointer;
763 nbytes = StrLength(IO->RecvBuf.Buf) - (pchh - pch);
764 snprintf(fn, SIZ, "/tmp/foolog_ev_%s.%d",
765 ((CitContext*)(IO->CitContext))->ServiceName,
768 fd = fopen(fn, "a+");
769 fprintf(fd, "Read: BufSize: %ld BufContent: [",
771 rv = fwrite(pchh, nbytes, 1, fd);
772 if (!rv) printf("failed to write debug to %s!\n", fn);
779 } else if (nbytes == 0) {
780 IO_Timeout_callback(loop, &IO->rw_timeout, revents);
782 } else if (nbytes == -1) {
783 // FD is gone. kick it.
784 StopClientWatchers(IO);
786 "EVENT: Socket Invalid! %s \n",
794 IO_postdns_callback(struct ev_loop *loop, ev_idle *watcher, int revents)
796 AsyncIO *IO = watcher->data;
797 IO->Now = ev_now(event_base);
798 EV_syslog(LOG_DEBUG, "event: %s\n", __FUNCTION__);
799 become_session(IO->CitContext);
800 assert(IO->DNS.Query->PostDNS);
801 switch (IO->DNS.Query->PostDNS(IO))
804 assert(IO->DNS.Fail);
805 switch (IO->DNS.Fail(IO)) {
807 //// StopClientWatchers(IO);
818 eNextState EvConnectSock(AsyncIO *IO,
820 double first_rw_timeout,
823 struct sockaddr_in egress_sin;
827 become_session(IO->CitContext);
830 IO->NextState = eReadMessage;
833 IO->NextState = eSendReply;
836 IO->SendBuf.fd = IO->RecvBuf.fd =
838 (IO->ConnectMe->IPv6)?PF_INET6:PF_INET,
842 if (IO->SendBuf.fd < 0) {
844 "EVENT: socket() failed: %s\n",
847 StrBufPrintf(IO->ErrMsg,
848 "Failed to create socket: %s",
850 IO->SendBuf.fd = IO->RecvBuf.fd = 0;
853 fdflags = fcntl(IO->SendBuf.fd, F_GETFL);
856 "EVENT: unable to get socket flags! %s \n",
858 StrBufPrintf(IO->ErrMsg,
859 "Failed to get socket flags: %s",
861 close(IO->SendBuf.fd);
862 IO->SendBuf.fd = IO->RecvBuf.fd = 0;
865 fdflags = fdflags | O_NONBLOCK;
866 if (fcntl(IO->SendBuf.fd, F_SETFL, fdflags) < 0) {
869 "EVENT: unable to set socket nonblocking flags! %s \n",
871 StrBufPrintf(IO->ErrMsg,
872 "Failed to set socket flags: %s",
874 close(IO->SendBuf.fd);
875 IO->SendBuf.fd = IO->RecvBuf.fd = 0;
878 /* TODO: maye we could use offsetof() to calc the position of data...
879 * http://doc.dvgu.ru/devel/ev.html#associating_custom_data_with_a_watcher
881 ev_io_init(&IO->recv_event, IO_recv_callback, IO->RecvBuf.fd, EV_READ);
882 IO->recv_event.data = IO;
883 ev_io_init(&IO->send_event, IO_send_callback, IO->SendBuf.fd, EV_WRITE);
884 IO->send_event.data = IO;
886 ev_timer_init(&IO->conn_fail, IO_connfail_callback, conn_timeout, 0);
887 IO->conn_fail.data = IO;
888 ev_timer_init(&IO->rw_timeout, IO_Timeout_callback, first_rw_timeout,0);
889 IO->rw_timeout.data = IO;
894 /* for debugging you may bypass it like this:
895 * IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1");
896 * ((struct sockaddr_in)IO->ConnectMe->Addr).sin_addr.s_addr =
897 * inet_addr("127.0.0.1");
899 if (IO->ConnectMe->IPv6) {
900 rc = connect(IO->SendBuf.fd,
901 &IO->ConnectMe->Addr,
902 sizeof(struct sockaddr_in6));
905 /* If citserver is bound to a specific IP address on the host, make
906 * sure we use that address for outbound connections.
909 memset(&egress_sin, 0, sizeof(egress_sin));
910 egress_sin.sin_family = AF_INET;
911 if (!IsEmptyStr(config.c_ip_addr)) {
912 egress_sin.sin_addr.s_addr = inet_addr(config.c_ip_addr);
913 if (egress_sin.sin_addr.s_addr == !INADDR_ANY) {
914 egress_sin.sin_addr.s_addr = INADDR_ANY;
917 /* If this bind fails, no problem; we can still use INADDR_ANY */
918 bind(IO->SendBuf.fd, (struct sockaddr *)&egress_sin, sizeof(egress_sin));
920 rc = connect(IO->SendBuf.fd,
921 (struct sockaddr_in *)&IO->ConnectMe->Addr,
922 sizeof(struct sockaddr_in));
926 EVM_syslog(LOG_DEBUG, "connect() immediate success.\n");
927 set_start_callback(event_base, IO, 0);
928 ev_timer_start(event_base, &IO->rw_timeout);
929 return IO->NextState;
931 else if (errno == EINPROGRESS) {
932 EVM_syslog(LOG_DEBUG, "connect() have to wait now.\n");
934 ev_io_init(&IO->conn_event,
935 IO_connestd_callback,
939 IO->conn_event.data = IO;
941 ev_io_start(event_base, &IO->conn_event);
942 ev_timer_start(event_base, &IO->conn_fail);
943 return IO->NextState;
946 ev_idle_init(&IO->conn_fail_immediate,
947 IO_connfailimmediate_callback);
948 IO->conn_fail_immediate.data = IO;
949 ev_idle_start(event_base, &IO->conn_fail_immediate);
951 EV_syslog(LOG_ERR, "connect() failed: %s\n", strerror(errno));
952 StrBufPrintf(IO->ErrMsg,
953 "Failed to connect: %s",
955 return IO->NextState;
957 return IO->NextState;
960 void SetNextTimeout(AsyncIO *IO, double timeout)
962 IO->rw_timeout.repeat = timeout;
963 ev_timer_again (event_base, &IO->rw_timeout);
967 eNextState ReAttachIO(AsyncIO *IO,
972 become_session(IO->CitContext);
973 ev_cleanup_start(event_base, &IO->abort_by_shutdown);
975 IO->NextState = eReadMessage;
978 IO->NextState = eSendReply;
980 set_start_callback(event_base, IO, 0);
982 return IO->NextState;
985 void InitIOStruct(AsyncIO *IO,
987 eNextState NextState,
988 IO_LineReaderCallback LineReader,
989 IO_CallBack DNS_Fail,
990 IO_CallBack SendDone,
991 IO_CallBack ReadDone,
992 IO_CallBack Terminate,
993 IO_CallBack DBTerminate,
994 IO_CallBack ConnFail,
996 IO_CallBack ShutdownAbort)
1000 IO->CitContext = CloneContext(CC);
1001 ((CitContext *)IO->CitContext)->session_specific_data = (char*) Data;
1003 IO->NextState = NextState;
1005 IO->SendDone = SendDone;
1006 IO->ReadDone = ReadDone;
1007 IO->Terminate = Terminate;
1008 IO->DBTerminate = DBTerminate;
1009 IO->LineReader = LineReader;
1010 IO->ConnFail = ConnFail;
1011 IO->Timeout = Timeout;
1012 IO->ShutdownAbort = ShutdownAbort;
1014 IO->DNS.Fail = DNS_Fail;
1016 IO->SendBuf.Buf = NewStrBufPlain(NULL, 1024);
1017 IO->RecvBuf.Buf = NewStrBufPlain(NULL, 1024);
1018 IO->IOBuf = NewStrBuf();
1019 EV_syslog(LOG_DEBUG,
1020 "EVENT: Session lives at %p IO at %p \n",
1025 extern int evcurl_init(AsyncIO *IO);
1027 int InitcURLIOStruct(AsyncIO *IO,
1030 IO_CallBack SendDone,
1031 IO_CallBack Terminate,
1032 IO_CallBack DBTerminate,
1033 IO_CallBack ShutdownAbort)
1037 IO->CitContext = CloneContext(CC);
1038 ((CitContext *)IO->CitContext)->session_specific_data = (char*) Data;
1040 IO->SendDone = SendDone;
1041 IO->Terminate = Terminate;
1042 IO->DBTerminate = DBTerminate;
1043 IO->ShutdownAbort = ShutdownAbort;
1045 strcpy(IO->HttpReq.errdesc, Desc);
1048 return evcurl_init(IO);
1052 extern int DebugEventLoopBacktrace;
1053 void EV_backtrace(AsyncIO *IO)
1055 #ifdef HAVE_BACKTRACE
1056 void *stack_frames[50];
1060 if ((IO == NULL) || (DebugEventLoopBacktrace == 0))
1062 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
1063 strings = backtrace_symbols(stack_frames, size);
1064 for (i = 0; i < size; i++) {
1065 if (strings != NULL) {
1066 EV_syslog(LOG_ALERT, " BT %s\n", strings[i]);
1069 EV_syslog(LOG_ALERT, " BT %p\n", stack_frames[i]);
1077 ev_tstamp ctdl_ev_now (void)
1079 return ev_now(event_base);