From: Stefan Metzmacher Date: Sat, 3 Jan 2009 11:39:11 +0000 (+0100) Subject: tevent: add tevent_fd_set_auto_close() X-Git-Tag: samba-4.0.0alpha6~283^2~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=193eba85a9a6eff7c314f6afaaeff6bf3cff1399;p=thirdparty%2Fsamba.git tevent: add tevent_fd_set_auto_close() tevent_fd_set_auto_close() is a simple wrapper arround tevent_fd_set_close_fn() with a callback that uses plain close(2). metze --- diff --git a/lib/tevent/testsuite.c b/lib/tevent/testsuite.c index ec57c5ad2eb..1b811f5fa2e 100644 --- a/lib/tevent/testsuite.c +++ b/lib/tevent/testsuite.c @@ -81,8 +81,9 @@ static bool test_event_context(struct torture_context *test, /* create a pipe */ pipe(fd); - fde = event_add_fd(ev_ctx, ev_ctx, fd[0], EVENT_FD_READ|EVENT_FD_AUTOCLOSE, + fde = event_add_fd(ev_ctx, ev_ctx, fd[0], EVENT_FD_READ, fde_handler, fd); + tevent_fd_set_auto_close(fde); event_add_timed(ev_ctx, ev_ctx, timeval_current_ofs(2,0), finished_handler, &finished); diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index 93918cc14dc..5582b583e73 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -53,6 +53,7 @@ */ #include "replace.h" +#include "system/filesys.h" #include "tevent.h" #include "tevent_internal.h" #include "tevent_util.h" @@ -250,6 +251,19 @@ void tevent_fd_set_close_fn(struct tevent_fd *fde, fde->event_ctx->ops->set_fd_close_fn(fde, close_fn); } +static void tevent_fd_auto_close_fn(struct tevent_context *ev, + struct tevent_fd *fde, + int fd, + void *private_data) +{ + close(fd); +} + +void tevent_fd_set_auto_close(struct tevent_fd *fde) +{ + tevent_fd_set_close_fn(fde, tevent_fd_auto_close_fn); +} + /* return the fd event flags */ diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h index 9d3b8aa39e8..b02c7854bc5 100644 --- a/lib/tevent/tevent.h +++ b/lib/tevent/tevent.h @@ -113,6 +113,7 @@ int tevent_loop_wait(struct tevent_context *ev); void tevent_fd_set_close_fn(struct tevent_fd *fde, tevent_fd_close_fn_t close_fn); +void tevent_fd_set_auto_close(struct tevent_fd *fde); uint16_t tevent_fd_get_flags(struct tevent_fd *fde); void tevent_fd_set_flags(struct tevent_fd *fde, uint16_t flags);