have an array of all started jobs
authorPierre Habouzit <madcoder@debian.org>
Sat, 12 Jan 2008 11:02:06 +0000 (12:02 +0100)
committerPierre Habouzit <madcoder@debian.org>
Sat, 12 Jan 2008 11:02:06 +0000 (12:02 +0100)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
lib-sys/evtloop.c
lib-sys/evtloop.h

index 4b2f0d8..3ecfb57 100644 (file)
 #include "mutt.h"
 #include "mutt_ssl.li"
 
 #include "mutt.h"
 #include "mutt_ssl.li"
 
+DO_ARRAY_TYPE(job_t, job);
+
 static int epollfd = -1;
 static int epollfd = -1;
+static job_array jobs;
 
 static int el_job_setemode(job_t *w, el_mode emode)
 {
 
 static int el_job_setemode(job_t *w, el_mode emode)
 {
@@ -78,6 +81,32 @@ void job_wipe(job_t *w)
         gnutls_deinit(w->session);
 }
 
         gnutls_deinit(w->session);
 }
 
+static void job_arrau_dtor(job_t **j)
+{
+    if (*j)
+        IGNORE(el_job_release(*j, EL_KILLED));
+}
+
+DO_ARRAY_FUNCS(job_t, job, job_arrau_dtor);
+
+static void job_array_remove(job_array *arr, job_t *j)
+{
+    for (int i = 0; i < arr->len; i++) {
+        if (arr->arr[i] == j) {
+            job_array_take(arr, i);
+            break;
+        }
+    }
+}
+
+job_t *el_job_start(const machine_t *m, void *cfg)
+{
+    job_t *w = job_new();
+    w->m = m;
+    job_array_append(&jobs, w);
+    return m->setup(w, cfg) < 0 ? NULL : w;
+}
+
 int el_job_release(job_t *w, el_status reason)
 {
     w->state = EL_LLP_FINI;
 int el_job_release(job_t *w, el_status reason)
 {
     w->state = EL_LLP_FINI;
@@ -89,6 +118,7 @@ int el_job_release(job_t *w, el_status reason)
             gnutls_bye(w->session, GNUTLS_SHUT_RDWR);
         close(w->fd);
     }
             gnutls_bye(w->session, GNUTLS_SHUT_RDWR);
         close(w->fd);
     }
+    job_array_remove(&jobs, w);
     job_delete(&w);
     return -1;
 }
     job_delete(&w);
     return -1;
 }
@@ -315,10 +345,12 @@ void el_initialize(void)
         mutt_error("epoll_create");
         mutt_exit(EXIT_FAILURE);
     }
         mutt_error("epoll_create");
         mutt_exit(EXIT_FAILURE);
     }
+    job_array_init(&jobs);
 }
 
 void el_shutdown(void)
 {
 }
 
 void el_shutdown(void)
 {
+    job_array_wipe(&jobs);
     close(epollfd);
     gnutls_global_deinit();
 }
     close(epollfd);
     gnutls_global_deinit();
 }
index c96f0c2..73c9ec5 100644 (file)
@@ -85,18 +85,15 @@ typedef struct machine_t {
     do { if ((expr) < 0) return -1; } while (0)
 
 __must_check__ int el_job_setmode(job_t *w, el_mode);
     do { if ((expr) < 0) return -1; } while (0)
 
 __must_check__ int el_job_setmode(job_t *w, el_mode);
+__must_check__ job_t *el_job_start(const machine_t *m, void *cfg);
 __must_check__ int el_job_release(job_t *j, el_status);
 __must_check__ int el_job_release(job_t *j, el_status);
+
 __must_check__ int el_job_connect(job_t *w, struct sockaddr *, socklen_t len,
                                   int type, int proto, int ssl);
 __must_check__ int el_job_starttls(job_t *w);
 __must_check__ ssize_t el_job_read(job_t *w, buffer_t *buf);
 __must_check__ ssize_t el_job_write(job_t *w, buffer_t *buf);
 
 __must_check__ int el_job_connect(job_t *w, struct sockaddr *, socklen_t len,
                                   int type, int proto, int ssl);
 __must_check__ int el_job_starttls(job_t *w);
 __must_check__ ssize_t el_job_read(job_t *w, buffer_t *buf);
 __must_check__ ssize_t el_job_write(job_t *w, buffer_t *buf);
 
-static inline job_t *el_job_start(const machine_t *m, void *cfg) {
-    job_t *w = job_new();
-    w->m = m;
-    return m->setup(w, cfg) < 0 ? NULL : w;
-}
 
 int el_dispatch(int timeout);
 void el_initialize(void);
 
 int el_dispatch(int timeout);
 void el_initialize(void);