2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * Copyright © 2006 Pierre Habouzit
20 #include <sys/epoll.h>
21 #include <sys/socket.h>
23 # include <linux/poll.h>
25 # define EPOLLRDHUP POLLRDHUP
33 static int epollfd = -1;
35 int el_job_release(job_t *w, el_status reason)
37 w->state = EL_LLP_FINI;
38 if (w->m && w->m->finalize) {
39 w->m->finalize(w, reason);
48 int el_dispatch(int timeout)
50 struct epoll_event events[FD_SETSIZE];
51 int count = epoll_wait(epollfd, events, countof(events), timeout);
54 if (errno == EAGAIN || errno == EINTR)
56 mutt_error("epoll_wait");
57 mutt_exit(EXIT_FAILURE);
60 while (--count >= 0) {
61 job_t *w = events[count].data.ptr;
62 int event = events[count].events;
71 if (event & EPOLLRDHUP) {
72 IGNORE(el_job_release(w, EL_RDHUP));
73 } else if (w->mode != w->emode) {
74 w->m->on_event(w, EL_EVT_INOUT ^ w->emode);
80 w->m->on_event(w, evt);
85 IGNORE(el_job_release(w, EL_ERROR));