* MA 02110-1301, USA.
*/
/*
- * Copyright © 2006 Pierre Habouzit
+ * Copyright © 2007 Pierre Habouzit
*/
#ifndef MUTT_LIB_SYS_EVTLOOP_H
#define MUTT_LIB_SYS_EVTLOOP_H
#include <lib-lib/lib-lib.h>
+#include <gnutls/gnutls.h>
+#include <sys/socket.h>
+#include "account.h"
typedef enum el_state {
EL_LLP_INIT,
} el_state;
typedef enum el_mode {
- EL_IDLE = 0,
+ EL_NEW = 0,
EL_READING = 1,
EL_WRITING = 2,
EL_RDWR = 3,
+ EL_IDLE = 4,
} el_mode;
typedef enum el_status {
typedef struct job_t {
int fd;
+ int ssf;
+ unsigned cond : 1;
el_state state : 2;
- el_mode mode : 2;
- el_mode emode : 2;
+ el_mode mode : 3;
+ el_mode emode : 3;
+ gnutls_session_t session;
+ gnutls_certificate_credentials_t xcred;
+
+ struct timeval mru;
int (*llp)(struct job_t *);
- struct machine_t *m;
+ const struct machine_t *m;
void *ptr;
} job_t;
+DO_INIT(job_t, job);
+void job_wipe(job_t *w);
+DO_NEW(job_t, job);
+DO_DELETE(job_t, job);
typedef struct machine_t {
const char *name;
__must_check__ int (*setup)(job_t *w, void *);
- int (*on_event)(job_t *w, el_event);
+ __must_check__ int (*on_event)(job_t *w, el_event);
void (*finalize)(job_t *w, el_status);
} machine_t;
+#define EL_JOB_CHECK(expr) \
+ 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_connect(job_t *w, struct sockaddr *, socklen_t len,
+ int type, int proto, int ssl);
+__must_check__ int el_job_connect2(job_t *w, const ACCOUNT *);
+__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);
+
+void el_lock(void);
+void el_unlock(void);
+void el_wait(volatile job_t *w);
+
int el_dispatch(int timeout);
+void el_initialize(void);
+void el_shutdown(void);
+
#endif