2 * Copyright (c) 1998-2009 by the citadel.org team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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>
47 #include <arpa/inet.h>
48 #include <libcitadel.h>
51 #include "citserver.h"
54 #include "ctdl_module.h"
56 #ifdef EXPERIMENTAL_SMTP_EVENT_CLIENT
58 #include "event_client.h"
60 int event_add_pipe[2];
62 citthread_mutex_t EventQueueMutex; /* locks the access to the following vars: */
63 void *QueueEventAddPtr = NULL;
64 EventContextAttach EventContextAttachPtr;
66 HashList *QueueEvents = NULL;
68 static struct event_base *event_base;
69 struct event queue_add_event;
71 static void QueueEventAddCallback(int fd, short event, void *ctx)
75 /* get the control command... */
79 EventContextAttachPtr(QueueEventAddPtr);
80 /// TODO: add it to QueueEvents
83 event_del(&queue_add_event);
84 close(event_add_pipe[0]);
85 /// TODO; flush QueueEvents fd's and delete it.
86 event_base_loopexit(event_base, NULL);
88 /* Unblock the other side */
93 * this thread operates the select() etc. via libevent.
97 void *client_event_thread(void *arg) {
98 struct CitContext libevent_client_CC;
99 event_base = event_init();
101 base = event_base_new();
103 return NULL; /*XXXerr*/
105 citthread_mutex_init(&EventQueueMutex, NULL);
106 CtdlFillSystemContext(&libevent_client_CC, "LibEvent Thread");
107 // citthread_setspecific(MyConKey, (void *)&smtp_queue_CC);
108 CtdlLogPrintf(CTDL_DEBUG, "client_event_thread() initializing\n");
110 if (pipe(event_add_pipe) != 0) {
111 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for libevent queueing: %s\n", strerror(errno));
115 event_set(&queue_add_event,
118 QueueEventAddCallback,
121 event_add(&queue_add_event, NULL);
125 CtdlClearSystemContext();
126 event_base_free(event_base);
127 citthread_mutex_destroy(&EventQueueMutex);
133 CTDL_MODULE_INIT(event_client)
135 #ifdef EXPERIMENTAL_SMTP_EVENT_CLIENT
138 CtdlThreadCreate("Client event", CTDLTHREAD_BIGSTACK, client_event_thread, NULL);
139 QueueEvents = NewHash(1, Flathash);
140 /// todo register shutdown callback.