]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/eventclient/serv_eventclient.c
libev migration: reinstantiate MX-Relay; unfinished.
[citadel.git] / citadel / modules / eventclient / serv_eventclient.c
index 68a45c7258fe186cfce0784fa6285cce0b3920d1..ec6af084e856aa51f08908fa2d4a29eac991c29b 100644 (file)
@@ -65,10 +65,10 @@ HashList *QueueEvents = NULL;
 HashList *InboundEventQueue = NULL;
 HashList *InboundEventQueues[2] = { NULL, NULL };
 
-static struct event_base *event_base;
-struct event queue_add_event;
+struct ev_loop *event_base;
+struct ev_io queue_add_event;
 
-static void QueueEventAddCallback(int fd, short event, void *ctx)
+static void QueueEventAddCallback(struct ev_loop *loop, ev_io *watcher, int revents)
 {
        char buf[10];
        HashList *q;
@@ -78,7 +78,7 @@ static void QueueEventAddCallback(int fd, short event, void *ctx)
        const char *Key;
 
        /* get the control command... */
-       read(fd, buf, 1);
+       read(watcher->fd, buf, 1);
        switch (buf[0]) {
        case '+':
                citthread_mutex_lock(&EventQueueMutex);
@@ -97,20 +97,18 @@ static void QueueEventAddCallback(int fd, short event, void *ctx)
                while (GetNextHashPos(q, It, &len, &Key, &v))
                {
                        IOAddHandler *h = v;
-                       h->EvAttch(h->Ctx);
+                       h->EvAttch(h->IO);
                }
                DeleteHashPos(&It);
                DeleteHashContent(&q);
 /// TODO: add it to QueueEvents
                break;
        case 'x':
-               event_del(&queue_add_event);
                close(event_add_pipe[0]);
 /// TODO; flush QueueEvents fd's and delete it.
-               event_base_loopexit(event_base, NULL);
+               ev_io_stop(event_base, &queue_add_event);
+               ev_unloop(event_base, EVUNLOOP_ALL);
        }
-       /* Unblock the other side */
-//     read(fd, buf, 1);
        CtdlLogPrintf(CTDL_DEBUG, "EVENT Q Read done.\n");
 }
 
@@ -119,16 +117,10 @@ void InitEventQueue(void)
 {
        struct rlimit LimitSet;
 
-       event_base = event_init();
-/*
-       base = event_base_new();
-       if (!base)
-               return NULL; / *XXXerr*/
-
        citthread_mutex_init(&EventQueueMutex, NULL);
 
        if (pipe(event_add_pipe) != 0) {
-               CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for libevent queueing: %s\n", strerror(errno));
+               CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for libev queueing: %s\n", strerror(errno));
                abort();
        }
        LimitSet.rlim_cur = 1;
@@ -141,30 +133,34 @@ void InitEventQueue(void)
        InboundEventQueue = InboundEventQueues[0];
 }
 /*
- * this thread operates the select() etc. via libevent.
+ * this thread operates the select() etc. via libev.
  * 
  * 
  */
 void *client_event_thread(void *arg) 
 {
        struct CitContext libevent_client_CC;
-       CtdlFillSystemContext(&libevent_client_CC, "LibEvent Thread");
+
+       CtdlFillSystemContext(&libevent_client_CC, "LibEv Thread");
 //     citthread_setspecific(MyConKey, (void *)&smtp_queue_CC);
-       CtdlLogPrintf(CTDL_DEBUG, "client_event_thread() initializing\n");
-       
-       event_set(&queue_add_event, 
-                 event_add_pipe[0], 
-                 EV_READ|EV_PERSIST,
-                 QueueEventAddCallback, 
-                 NULL);
-       
-       event_add(&queue_add_event, NULL);
+       CtdlLogPrintf(CTDL_DEBUG, "client_ev_thread() initializing\n");
 
+       event_base = ev_default_loop (EVFLAG_AUTO);
 
-       event_dispatch();
+       ev_io_init(&queue_add_event, QueueEventAddCallback, event_add_pipe[0], EV_READ);
+       ev_io_start(event_base, &queue_add_event);
+
+       ev_loop (event_base, 0);
        CtdlClearSystemContext();
-       event_base_free(event_base);
+       ev_default_destroy ();
+       
+       DeleteHash(&QueueEvents);
+       InboundEventQueue = NULL;
+       DeleteHash(&InboundEventQueues[0]);
+       DeleteHash(&InboundEventQueues[1]);
        citthread_mutex_destroy(&EventQueueMutex);
+
+
        return(NULL);
 }