diff options
author | Stefan Metzmacher <metze@samba.org> | 2009-01-05 17:36:50 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2009-01-05 22:44:53 +0100 |
commit | ceac26008c6f36602259d0180f1e7f7a756ea4ad (patch) | |
tree | 31df7bfbfdf29dc922e481b1fe163fd4e4a21404 /lib/tevent/tevent_aio.c | |
parent | b24924d6a6438b361fb903227bd56d2afe40d2f2 (diff) | |
download | samba-ceac26008c6f36602259d0180f1e7f7a756ea4ad.tar.gz samba-ceac26008c6f36602259d0180f1e7f7a756ea4ad.tar.bz2 samba-ceac26008c6f36602259d0180f1e7f7a756ea4ad.zip |
tevent: keep a linked list of fd_events
metze
Diffstat (limited to 'lib/tevent/tevent_aio.c')
-rw-r--r-- | lib/tevent/tevent_aio.c | 48 |
1 files changed, 13 insertions, 35 deletions
diff --git a/lib/tevent/tevent_aio.c b/lib/tevent/tevent_aio.c index 28134bef5e..330794f8c5 100644 --- a/lib/tevent/tevent_aio.c +++ b/lib/tevent/tevent_aio.c @@ -47,12 +47,6 @@ struct aio_event_context { /* a pointer back to the generic event_context */ struct tevent_context *ev; - /* list of filedescriptor events */ - struct tevent_fd *fd_events; - - /* number of registered fd event handlers */ - int num_fd_events; - uint32_t destruction_count; io_context_t ioctx; @@ -118,7 +112,7 @@ static void epoll_check_reopen(struct aio_event_context *aio_ev) return; } aio_ev->pid = getpid(); - for (fde=aio_ev->fd_events;fde;fde=fde->next) { + for (fde=aio_ev->ev->fd_events;fde;fde=fde->next) { epoll_add_event(aio_ev, fde); } } @@ -159,8 +153,6 @@ static void epoll_del_event(struct aio_event_context *aio_ev, struct tevent_fd * { struct epoll_event event; - DLIST_REMOVE(aio_ev->fd_events, fde); - if (aio_ev->epoll_fd == -1) return; fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; @@ -219,7 +211,6 @@ static void epoll_change_event(struct aio_event_context *aio_ev, struct tevent_f /* there's no aio_event attached to the fde */ if (want_read || (want_write && !got_error)) { - DLIST_ADD(aio_ev->fd_events, fde); epoll_add_event(aio_ev, fde); return; } @@ -389,22 +380,20 @@ static int aio_event_context_init(struct tevent_context *ev) static int aio_event_fd_destructor(struct tevent_fd *fde) { struct tevent_context *ev = fde->event_ctx; - struct aio_event_context *aio_ev = talloc_get_type(ev->additional_data, - struct aio_event_context); + struct aio_event_context *aio_ev = NULL; - epoll_check_reopen(aio_ev); + if (ev) { + aio_ev = talloc_get_type(ev->additional_data, + struct aio_event_context); - aio_ev->num_fd_events--; - aio_ev->destruction_count++; + epoll_check_reopen(aio_ev); - epoll_del_event(aio_ev, fde); + aio_ev->destruction_count++; - if (fde->close_fn) { - fde->close_fn(ev, fde, fde->fd, fde->private_data); - fde->fd = -1; + epoll_del_event(aio_ev, fde); } - return 0; + return tevent_common_fd_destructor(fde); } /* @@ -424,24 +413,13 @@ static struct tevent_fd *aio_event_add_fd(struct tevent_context *ev, TALLOC_CTX epoll_check_reopen(aio_ev); - fde = talloc(mem_ctx?mem_ctx:ev, struct tevent_fd); + fde = tevent_common_add_fd(ev, mem_ctx, fd, flags, + handler, private_data, + handler_name, location); if (!fde) return NULL; - fde->event_ctx = ev; - fde->fd = fd; - fde->flags = flags; - fde->handler = handler; - fde->close_fn = NULL; - fde->private_data = private_data; - fde->handler_name = handler_name; - fde->location = location; - fde->additional_flags = 0; - fde->additional_data = NULL; - - aio_ev->num_fd_events++; talloc_set_destructor(fde, aio_event_fd_destructor); - DLIST_ADD(aio_ev->fd_events, fde); epoll_add_event(aio_ev, fde); return fde; @@ -493,7 +471,7 @@ static int aio_event_loop_wait(struct tevent_context *ev) { struct aio_event_context *aio_ev = talloc_get_type(ev->additional_data, struct aio_event_context); - while (aio_ev->num_fd_events) { + while (aio_ev->ev->fd_events) { if (aio_event_loop_once(ev) != 0) { break; } |