diff options
Diffstat (limited to 'accel-pppd/triton/md.c')
-rw-r--r-- | accel-pppd/triton/md.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/accel-pppd/triton/md.c b/accel-pppd/triton/md.c index 1396d3ec..6067ff2e 100644 --- a/accel-pppd/triton/md.c +++ b/accel-pppd/triton/md.c @@ -5,6 +5,7 @@ #include <string.h> #include <errno.h> #include <unistd.h> +#include <fcntl.h> #include "triton_p.h" @@ -32,6 +33,8 @@ int md_init(void) return -1; } + fcntl(epoll_fd, F_SETFD, O_CLOEXEC); + epoll_events = _malloc(max_events * sizeof(struct epoll_event)); if (!epoll_events) { fprintf(stderr,"md:cann't allocate memory\n"); @@ -171,15 +174,22 @@ int __export triton_md_enable_handler(struct triton_md_handler_t *ud, int mode) if (mode & MD_MODE_WRITE) h->epoll_event.events |= EPOLLOUT; - if (!h->trig_level) + if (h->trig_level) + h->epoll_event.events |= EPOLLONESHOT; + else h->epoll_event.events |= EPOLLET; if (events == h->epoll_event.events) return 0; - if (events) - r = epoll_ctl(epoll_fd, EPOLL_CTL_MOD, h->ud->fd, &h->epoll_event); - else + if (events) { + if (h->armed) + r = epoll_ctl(epoll_fd, EPOLL_CTL_MOD, h->ud->fd, &h->epoll_event); + else { + h->mod = 1; + r = 0; + } + } else r = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, h->ud->fd, &h->epoll_event); if (r) { @@ -204,13 +214,21 @@ int __export triton_md_disable_handler(struct triton_md_handler_t *ud,int mode) if (mode & MD_MODE_WRITE) h->epoll_event.events &= ~EPOLLOUT; + if (!(h->epoll_event.events & (EPOLLIN | EPOLLOUT))) + h->epoll_event.events = 0; + if (events == h->epoll_event.events) return 0; - if (h->epoll_event.events & (EPOLLIN | EPOLLOUT)) - r = epoll_ctl(epoll_fd, EPOLL_CTL_MOD, h->ud->fd, &h->epoll_event); - else { - h->epoll_event.events = 0; + if (h->epoll_event.events) { + if (h->armed) + r = epoll_ctl(epoll_fd, EPOLL_CTL_MOD, h->ud->fd, &h->epoll_event); + else { + h->mod = 1; + r = 0; + } + } else { + h->mod = 0; r = epoll_ctl(epoll_fd, EPOLL_CTL_DEL, h->ud->fd, NULL); } @@ -228,3 +246,13 @@ void __export triton_md_set_trig(struct triton_md_handler_t *ud, int mode) h->trig_level = mode; } +void md_rearm(struct _triton_md_handler_t *h) +{ + if (h->mod) { + epoll_ctl(epoll_fd, EPOLL_CTL_MOD, h->ud->fd, &h->epoll_event); + h->mod = 0; + } + + h->armed = 1; +} + |